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
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