W
Westeral
I currently use Ken Snell's browse to a folder dialogue and pick a file to
import into a table. Since there are multiple files of the same format but
with different names I wanted to use his browse to a folder and import all
the Excel files in that folder and then delete them. I can get it to browse
to the right folder but it does not import or delete the file. His code
follows (I do have the module for the API also). Am I missing something or is
there an error in the code or something I have to add? Thanks.
Private Sub Command23_Click()
Dim strPathFile As String, strFile As String, strPath As String
Dim strTable As String, strBrowseMsg As String
Dim blnHasFieldNames As Boolean
' Change this next line to True if the first row in EXCEL worksheet
' has field names
blnHasFieldNames = True
strBrowseMsg = "Select the folder that contains the EXCEL files:"
strPath = BrowseFolder(strBrowseMsg)
If strPath = "" Then
MsgBox "No folder was selected.", vbOK, "No Selection"
Exit Sub
End If
' Replace tablename with the real name of the table into which
' the data are to be imported
strTable = "tblCaseReviews"
strFile = Dir(strPath & "*.xls")
Do While Len(strFile) > 0
strPathFile = strPath & strFile
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, strTable,
strPathFile, blnHasFieldNames
' Uncomment out the next code step if you want to delete the
' EXCEL file after it's been imported
Kill strPathFile
strFile = Dir()
Loop
End Sub
import into a table. Since there are multiple files of the same format but
with different names I wanted to use his browse to a folder and import all
the Excel files in that folder and then delete them. I can get it to browse
to the right folder but it does not import or delete the file. His code
follows (I do have the module for the API also). Am I missing something or is
there an error in the code or something I have to add? Thanks.
Private Sub Command23_Click()
Dim strPathFile As String, strFile As String, strPath As String
Dim strTable As String, strBrowseMsg As String
Dim blnHasFieldNames As Boolean
' Change this next line to True if the first row in EXCEL worksheet
' has field names
blnHasFieldNames = True
strBrowseMsg = "Select the folder that contains the EXCEL files:"
strPath = BrowseFolder(strBrowseMsg)
If strPath = "" Then
MsgBox "No folder was selected.", vbOK, "No Selection"
Exit Sub
End If
' Replace tablename with the real name of the table into which
' the data are to be imported
strTable = "tblCaseReviews"
strFile = Dir(strPath & "*.xls")
Do While Len(strFile) > 0
strPathFile = strPath & strFile
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, strTable,
strPathFile, blnHasFieldNames
' Uncomment out the next code step if you want to delete the
' EXCEL file after it's been imported
Kill strPathFile
strFile = Dir()
Loop
End Sub