Hi I am trying to load a vba code in the backbround of a form comand:
where I want to download many txt files into tables.
Seems I can do only one at a time.
for sure my code is missing smth, can smb have a look and tell me what?
thanks
Private Sub Command1_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
strTable = "orders"
strSpecification = "orders"
blnHasFieldNames = False
intImportType = acImportDelim
strTable = "cust"
strSpecification = "cust"
blnHasFieldNames = False
intImportType = acImportDelim
strTable = "shops"
strSpecification = "shops"
blnHasFieldNames = False
intImportType = acImportDelim
' Let user select a folder
With Application.FileDialog(4)
If .Show Then
strPath = .SelectedItems(1)
Else
MsgBox "You didn't select a folder", vbExclamation
Exit Sub
End If
End With
If Right(strPath, 1) <> "\" Then
strPath = strPath & "\"
End If
DoCmd.OpenForm "frmMessage"
Forms!frmMessage.Repaint
' 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
DoCmd.Close acForm, "frmMessage"
End Sub
End Sub