Prompt for file name

SiGill

Registered User.
Local time
Yesterday, 19:29
Joined
Dec 22, 2008
Messages
72
Hi Have this function in access that allows me to propmt for a file name to be imported.

Function Import_File_Click()

On Error GoTo Err_Import_File_Click

Dim strFile_Path As String
Dim strTable As String

'Prompt user for file path
strFile_Path = InputBox("Please enter file path V")
'Prompt user for name of table to create for imported data
strTable = InputBox("Please enter name of new table")

'Import file, using inputted file path and table name
DoCmd.TransferText acImportDelim, , strTable, strFile_Path

Exit_Import_File_Click:
Exit Function

Err_Import_File_Click:
If Err.Number = 3011 Then
MsgBox strFile_Path & " is not a valid path, please try again", vbExclamation, "Invalid File Path"
Else
MsgBox Err.Description
End If
Resume Exit_Import_File_Click

End Function

Can I adapt it to do 3 extra things.

1. Can I add an Import Specification. Am having problems if the first line of what I am importing is numeric, the text values on the lines that follow error.

2. Can I add in a bit where the filename is file location is filled out. i.e. c:/temp/ then all I have to put is the filename i.e. myfile.csv

3. I am only importing to one table. Can the table field already be filled out. i.e. It imports everything to table MYTABLE

Any help would be appreciated
 
a database would have to posted i'm sure to help you in detail here. but i'll help you out one...

consider changing the method and using the file picker. when files are selected, the program automatically captures them and shoves em into an array that is represented by the .selecteditems() property of the picker. you can get the full path simply by asking what indexed object you want.
 

Users who are viewing this thread

Back
Top Bottom