I am importing all Excel Files in a folder - It works up to the point of updating the Field FileName with the file name of the Excel File.
Please Help. Here is my Code.
Private Sub Command2_Click()
Dim strPathFile As String, strFile As String, strPath As String
Dim strTable As String
Dim blnHasFieldNames As Boolean
Dim DB As DAO.Database
Dim STRSQL As String
' Change this next line to True if the first row in EXCEL worksheet
' has field names
blnHasFieldNames = False
' Replace C:\Documents\ with the real path to the folder that
' contains the EXCEL files
strPath = "C:\Users\larry.wolf\Desktop\davids\1\"
' Replace tablename with the real name of the table into which
' the data are to be imported
strTable = "tablename2"
strFile = Dir(strPath & "*.xls")
Do While Len(strFile) > 0
strPathFile = strPath & strFile
Dim temp As String
temp = strFile
On Error Resume Next
Set objExcel = GetObject(, "Excel.Application")
If Err.Number <> 0 Then
Set objExcel = CreateObject("Excel.Application")
blnEXCEL = True
End If
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
strTable, strPathFile, blnHasFieldNames
STRSQL = "UPDATE tablename2 SET tablename2.FileName = '" & temp & "' WHERE (((tablename2.FileName) Is Null));"
DoCmd.RunSQL (STRSQL)
strFile = Dir
' 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