J
Jason
Hello.. and thank you for participating in this awesome site. I have a problem that I hope someone has a quick solution for as I am pressed for time.
The following code searches a directory and imports all data from all .xls files in that directory. This works fantastic. The problem is that if I click the command button more than once, duplicates of all imported data is entered.
What I NEED to do is simply ammend the code to MOVE all .xls files to a subdirectory named "archive". That's it. I was thinking this simply be done at the end of the function? Thanks in advance, and have a great day!
Private Sub Command24_Click()
LocateFile ("*.xls") ' calls the LocateFile function and uses * for wildcard for strfilename to match.
End Sub
Function LocateFile(strFileName As String)
Dim vItem As Variant
With Application.FileSearch
.FileName = strFileName
.LookIn = "C:\mydirectory" 'path to xls files
.SearchSubFolders = False 'leave as false, don't want to search in lower folders.
.Execute
For Each vItem In .FoundFiles
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "MyTable", vItem, True, ""
Next vItem
'maybe include move instruction here?
End With
End Function
*THHANKS in advance
The following code searches a directory and imports all data from all .xls files in that directory. This works fantastic. The problem is that if I click the command button more than once, duplicates of all imported data is entered.
What I NEED to do is simply ammend the code to MOVE all .xls files to a subdirectory named "archive". That's it. I was thinking this simply be done at the end of the function? Thanks in advance, and have a great day!
Private Sub Command24_Click()
LocateFile ("*.xls") ' calls the LocateFile function and uses * for wildcard for strfilename to match.
End Sub
Function LocateFile(strFileName As String)
Dim vItem As Variant
With Application.FileSearch
.FileName = strFileName
.LookIn = "C:\mydirectory" 'path to xls files
.SearchSubFolders = False 'leave as false, don't want to search in lower folders.
.Execute
For Each vItem In .FoundFiles
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "MyTable", vItem, True, ""
Next vItem
'maybe include move instruction here?
End With
End Function
*THHANKS in advance