I have the following code that I've built thru some help and searching here on this forum (Thanks a million to all the great help here). I'm getting a Compile error: Invalid outside procedure message box on the "Set objFileDialog =" line.
Any idea where to move it or how to get around this? I need this code to work on the click of the button which it begins to, but then hits the error on this particular line.
Thanks!
Code:
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 = "Daily Aeppays Consolidated"
strSpecification = "DailyAeppayImport"
blnHasFieldNames = True
intImportType = acImportDelim
'***************************************
'Let user select a folder
With objFileDialog
.AllowMultiSelect = False 'Meaningless, but set anyway
.ButtonName = "Folder Picker"
.Title = "Folder Picker"
If .Show Then
strPath = .SelectedItems(1) & "\"
'Loop through the text files
strFile = Dir(strPath & "*.txt")
Do While strFile <> ""
'For Testing purposes only
DoCmd.TransferText intImportType, , strTable, strPath & strFile, False
strFile = Dir
Loop
End If
End With
Thanks!
Comment