I was wondering if anyone has had an issue where using vba code to
read an excel file and import the data into an access table some
records are not imported from the excel file. It seems looking at the
data in the excel file that if the first character in the excel file
cell is numeric it will read and write only numeric values only. If I
sort the coloumn in the excel file and the first character in the cell
read is alphanumeric then only alphanumeric values will read and write
in to the table. Any help would be greatly appreciated cause I am
going nuts here. I am using access 2000 and excel 2000. The code I am
using is as follows:
Dim dbExcel As Database
Dim thisdb As Recordset
Dim mydb As Database
Dim ITABLE As Recordset
Dim boolfound As Boolean
Dim i As Integer
Dim intpressedcancel As Integer
On Error GoTo whatthebeephappened:
'call open dialog box module
ShowOpen
boolfound = False
DoCmd.Hourglass True
Set mydb = DBEngine.Workspaces(0).Databases(0) 'Current DB
Set ITABLE = mydb.OpenRecordset("IMPORTED_TABLE", dbOpenTable) 'Import
Table
'Code used to open excel sheet as database rather than as excel object
Set dbExcel = OpenDatabase(FileName, False, True, "excel 8.0")
'loop used for each worksheet in workbook( there should only be one
but just in case)
'For i = 0 To dbExcel.TableDefs.Count - 1
strName = dbExcel.TableDefs(i).Name
Set thisdb = dbExcel.OpenRecordset(strName, dbOpenSnapshot)
thisdb.MoveLast
thisdb.MoveFirst
'code to skip importing of headings
'thisdb.AbsolutePosition = 1
Do While Not thisdb.EOF
If Not Left(thisdb.Fields(2), 3) = "Nex" Then '
'thisdb.MoveNext
'ElseIf thisdb.Fields(2).Value Then
With ITABLE
.AddNew
.Fields(0).Value = thisdb.Fields(3).Value ' SERIES
.Fields(1).Value = thisdb.Fields(4).Value ' VIN
.Fields(2).Value = thisdb.Fields(6).Value ' ENGINE NO
.Fields(3).Value = thisdb.Fields(0).Value ' RETAILER
.Fields(6).Value = thisdb.Fields(5).Value ' REPAIR
ORDER NO.
.Fields(7).Value = thisdb.Fields(7).Value ' REPAIR
DATE
.Fields(8).Value = thisdb.Fields(19).Value ' ODOMETER
.Fields(9).Value = thisdb.Fields(8) ' CAUSAL PART
.Fields(10).Value = thisdb.Fields(17).Value ' LABOUR
CODE
.Fields(11).Value = thisdb.Fields(18).Value ' LABOUR
Hours
.Fields(13).Value = thisdb.Fields(11).Value ' PART
COST
.Fields(14).Value = thisdb.Fields(12).Value ' LABOUR
COST
.Fields(15).Value = thisdb.Fields(14).Value ' NET ITEM
COST
.Fields(16).Value = thisdb.Fields(13).Value ' SALES
TAX
.Fields(17).Value = thisdb.Fields(16).Value ' TOTAL
.Fields(18).Value = thisdb.Fields(19).Value ' PAYMENT
.Fields(19).Value = thisdb.Fields(20).Value ' CASE
TYPE
.Fields(20).Value = thisdb.Fields(10).Value ' Nature
CODE
.Fields(37).Value = thisdb.Fields(9).Value ' Cause
code
.Fields(27).Value = thisdb.Fields(15).Value ' HANDLING
.Fields(29).Value = thisdb.Fields(24).Value '
AUTHORISED BY
.Fields(30).Value = thisdb.Fields(1).Value ' Sequence
.Update
End With
End If
thisdb.MoveNext
Loop
'Next i