mreference
Registered User.
- Local time
- Today, 17:14
- Joined
- Oct 4, 2010
- Messages
- 137
I am using the following code to import records into a table if they meet certain criteria, then once it has been imported, the file is moved to another location. This works extremely well.
What I would like to include is a message box that prompts the user that no files are currently available to import.
But if I inlucde this as part of an Else If or Else or even a new IF statement, I get this error message
or the message box keeps popping up a few times as it is presumably stuck in the For Each Loop.
Could somebody point me in the right direction, so that if no files exist I get the pop up message box once.
cheers
Code:
Private Sub bImportFiles_Click()
On Error GoTo bImportFiles_Click_Err
Dim objFS As Object, objFolder As Object
Dim objFiles As Object, objF1 As Object
Dim strFolderPath As String
strFolderPath = "C:\Amazon\MerchantTransport\production\report s\"
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFS.GetFolder(strFolderPath)
Set objFiles = objFolder.files
For Each objF1 In objFiles
If Right(objF1.Name, 3) = "txt" Then
DoCmd.TransferText acImportDelimited, "OrderAmazon", "tblOrdersAmazon", strFolderPath & objF1.Name, False
Name strFolderPath & objF1.Name As "C:\Amazon\MerchantTransport\production\report s\" & objF1.Name 'Move the files to the archive folder
End If
Next
Set objF1 = Nothing
Set objFiles = Nothing
Set objFolder = Nothing
Set objFS = Nothing
bImportFiles_Click_Exit:
Exit Sub
bImportFiles_Click_Err:
MsgBox Err.Number & " " & Err.Description
Resume bImportFiles_Click_Exit
End Sub
Code:
MsgBox "There are currently no records to import." & _
vbCrLf & "Please try again later."
Code:
Error 91: Object variable or With block variable not set
Could somebody point me in the right direction, so that if no files exist I get the pop up message box once.
cheers