Hi,
Please can you assist. I am trying to import multiple spreadsheets from a folder into an access database. This is working - however when trying to update the table with the file name, I receive an error.![]()
![]()
Please see below, the code I am using...
Function DoImport()
Dim strPathFile As String, strFile As String, strPath As String
Dim strTable As String
Dim blnHasFieldNames As Boolean
' New
Dim SQL As String
' Change this next line to True if the first row in EXCEL worksheet
' has field names
blnHasFieldNames = True
' Replace C:\Documents\ with the real path to the folder that
' contains the EXCEL files
strPath = "C:\QlikView Reports\Importing with file name"
' Replace tablename with the real name of the table into which
' the data are to be imported
strTable = "Import"
strFile = Dir(strPath & "*.xls")
Do While Len(strFile) > 0
strPathFile = strPath & strFile
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
strTable, strPathFile, blnHasFieldNames
'new
DoCmd.RunSQL
"UPDATE [Import] SET Import.[File Name]= & strFile & WHERE Import.[File Name] IS NULL OR Import.[File Name]='';""
' 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 Function
Thank you v much![]()