abenitez77
Registered User.
- Local time
- Today, 09:48
- Joined
- Apr 29, 2010
- Messages
- 141
I am looping thru and linking excel files. Sometimes there is data with the top row having title names. The problem is that when the column names are like "date" and "quatity" then when it links in what shows in the cell is "#Num!". How can I get around this so I see "date" and the other field names.? I don't want to set to true for the headers arguement because I want the columns to have the F1,F2,F3 etc...
Code:
Set wkb = objXL.Workbooks.Open(strFileName)
ShtCount = wkb.Sheets.count
i = 1
x = 1
For Each wks In wkb.Worksheets
' Link each sheet of the entire Spreadsheet file -----------------------
'DoCmd.TransferSpreadsheet acLink, , _
' shortFilename & "_~" & wks.Name, strFileName, False, wks.Name & "$"
'Progress Bar :::::::::::::::::::::::::::::::::::::
RetVal = SysCmd(acSysCmdInitMeter, "Linking FILE: " & PathFilename & " - SHEET: " & Trim(str(x)) & " of " & Trim(str(ShtCount)), ShtCount)
'Update the progress meter.
RetVal = SysCmd(acSysCmdUpdateMeter, i)
'TabName = wks.Name
DoCmd.TransferSpreadsheet acLink, , _
"TmpLinkXLS", strFileName, False, wks.Name & "$"
' Get the list of field names
'Set tdf = db.TableDefs("[" & shortFilename & "_~" & wks.Name & "]")
Set tdf = db.TableDefs("TmpLinkXLS")
' ---- Pause 1 second ------
Const cTIME = 1000 'in MilliSeconds
Call sSleep(cTIME)
myfields = ""
For Each fld In tdf.Fields
myfields = myfields & "[" & fld.Name & "],"
Next
'myfields = Mid(myfields, 1, Len(myfields) - 1)
i = i + 1
RetVal = SysCmd(acSysCmdInitMeter, "Inserting FILE: " & PathFilename & " - SHEET: " & Trim(str(x)) & " of " & Trim(str(ShtCount)), ShtCount)
'Update the progress meter.
RetVal = SysCmd(acSysCmdUpdateMeter, i)
' Insert the data from the sheet into the local XLSData Table --------------------------
'strsql = "Insert Into XLSData(" & myfields & "Fullimagepath,TabName" & ") Select " & myfields & Chr(34) & strFileName & Chr(34) & " as Fullimagepath, " & wks.Name & " as TabName From [" & shortFilename & "_~" & wks.Name & "] "
strsql = "Insert Into XLSData(" & myfields & "Fullimagepath,TabName" & ") " & _
" Select " & myfields & Chr(34) & strFileName & Chr(34) & " as Fullimagepath, " & Chr(34) & wks.Name & Chr(34) & " as TabName " & _
" From TmpLinkXLS As x1 " & _
" Where Len(Trim(x1.F1)) > 0 OR Len(Trim(x1.F2)) > 0 OR Len(Trim(x1.F3)) > 0 OR Len(Trim(x1.F4)) > 0 OR Len(Trim(x1.F5)) > 0 OR Len(Trim(x1.F6)) > 0 OR Len(Trim(x1.F7)) > 0 OR Len(Trim(x1.F8)) > 0 OR Len(Trim(x1.F8)) > 0 "
CurrentDb.Execute strsql, dbFailOnError
' ---- Pause 1 second ------
'Const cTIME = 1000 'in MilliSeconds
Call sSleep(cTIME)
i = i + 1
RetVal = SysCmd(acSysCmdInitMeter, "Dropping TmpLinkXLS", ShtCount)
'Update the progress meter.
RetVal = SysCmd(acSysCmdUpdateMeter, i)
If TableExists("TmpLinkXLS") Then
CurrentDb.Execute "Drop Table TmpLinkXLS", dbFailOnError
End If
Set tdf = Nothing
RetVal = SysCmd(acSysCmdInitMeter, " ", 0)
RetVal = SysCmd(acSysCmdRemoveMeter)
i = 1
x = x + 1
'DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
' wks.Name, strFileName, True, wks.Name & "$"
Next