I am trying to import multiple text files into an Access table. I build a Form with a button, named "Import_Dea ls". In the On click Event trigger I entered the following code, but it don't import my files. can someone please help?
Thanks,
Mike
Thanks,
Mike
Code:
Private Sub Import_Deals_Click() Dim strPath As String Dim strFile As String Dim strTable As String Dim strSpecification As String Dim intImportType As AcTextTransferType Dim blnHasFieldNames As Boolean Dim objFileDialog As Office.FileDialog Set objFileDialog = Application.FileDialog(MsoFileDialogType.msoFileDialogFolderPicker) ' Modify these values as needed strTable = "EERS_Deals" strSpecification = "EERS_Deals" blnHasFieldNames = False intImportType = acImportDelim ' Let user select a folder With objFileDialog .AllowMultiSelect = True .ButtonName = "Folder Picker" .Title = "Folder Picker" If (.SelectedItems.Count > 0) Then Call MsgBox(.SelectedItems(1)) ElseIf .Show > 0 Then End If End With If Right(strPath, 1) <> "\" Then strPath = strPath & "\" End If ' Loop through the text files strFile = Dir(strPath & "*.txt") Do While strFile <> "" ' Import text file DoCmd.TransferText _ TransferType:=intImportType, _ SpecificationName:=strSpecification, _ TableName:=strTable, _ FileName:=strPath & strFile, _ HasFieldNames:=blnHasFieldNames strFile = Dir Loop End Sub
Comment