The code you downloaded goes in a standard module. It doesn't matter what yo
name it as long as it is not the same name as any function or sub in the
module. Mine is named modBrowseFolders.
To allow the user to select the folder, you call the BrowseFolder function.
It has only one argument which is a string that will put a message at the top
of the dialog. This will give you the starting directory. Then you use the
Dir function to begin retrieving file names and importing them into your
table. You can use standard wild cards to limit the names and types of files
that will be returned.
What you have to be aware of is that the TransferSpreadsheet method will
overwrite the data in an existing table. Since you want to import multiple
worksheets into one table, you will need to allow for that. I suggest rather
than an import, you link the spreadsheets as a table and transfer the data. I
would recommend you create an Append query that copies records from the
spreadsheet table into your Access table.
The order of events is:
Get a folder to use from the user.
Retrieve a filename using the Dir function
Link to the file
Run the Append query to copy in the data
Use the DeleteObject method the destroy the link
Repeat until all matching files have been imported.
Dim StrFolder As String
Dim strFullName As String
Dim dbf As Database
Const conFilter As String = "\*.xls"
Set dbf = CurrentDb
strFolder = BrowseFolder("Select Folder For Imports")
If Len(strFolder) = 0 Then
MsgBox "Import Canceled"
Exit Sub
End If
strFullName = Dir(strFolder & conFilter)
Do While Len(strFullName) <> 0
dbf.Execute("DELETE * FROM tblXlImport;"), dbFailOnError
DoCmd.TransferSpreadsheet, acLink, , "tblXlImport", strFullName, True
dbf.Execute("qappXlImport"), dbFailOnError
DoCmd.DeleteObject acTable, "tblXlImport"
Dir()
Loop
dbf.Execute("DELETE * FROM tblXlImport;"), dbFailOnError
Set dbf = Nothing
Im alittle lost on this I looked at the code but im not usre how to use that
along with what you posted. Could you help me?
[quoted text clipped - 43 lines]