Hi Guys,
I have a written a code for a button in a form to import text files with the following field names in the text file.
Title LastName Firstname Address City State
Please see the below code and help me in finding the issue with the code.
When I click the button it throws the error "Field 'F1' doesn't exist in destination table "test"
Please advise me to proceed further.
I have a written a code for a button in a form to import text files with the following field names in the text file.
Title LastName Firstname Address City State
Please see the below code and help me in finding the issue with the code.
Code:
Private Sub Command27_Click()
Dim fdialog As FileDialog
Dim varFile As Variant
DoCmd.SetWarnings False
'Set up the File Dialog
Set fdialog = Application.FileDialog(msoFileDialogFilePicker)
With fdialog
.AllowMultiSelect = False
.Title = "Select a Text File to Import"
.InitialFileName = "C:\*.txt"
'Clear out any Filters, then Add you own (1)
.Filters.Add "Text Files", "*.TXT"
'Show the Dialog. If the Show Method returns True, the User picked
'at least 1 File, otherwise the User clicked Cancel
If .Show Then
For Each varFile In .SelectedItems
'There will be only 1 File selected, so place the proper Arguments into the TransferText Method
DoCmd.TransferText acImportDelim, , Tablename:="Test", FileName:="test.txt", hasfieldnames:=False
Next
Else
'Nothing selected in File Dialog
End If
End With
DoCmd.SetWarnings True
End Sub
When I click the button it throws the error "Field 'F1' doesn't exist in destination table "test"
Please advise me to proceed further.
Last edited: