Hi,
I have an append query to insert some data into a table from ms excel. Heres the code:
The issue is that it wont append the whole data. THe total data it needs to append is 174, but instead it only does 25. And there are some autonumber that jumps (i.e after 1011 then 1040)
I have checked using debug.print and it seems perfectly fine (I can see 174 records in Immediate Window), so my suspect is the docmd.runsql insQry...but what happen?anyone can help?
Thanks
I have an append query to insert some data into a table from ms excel. Heres the code:
Code:
Dim partNum As String
Dim desc As String
Dim Material As String
Dim cost As Long
Dim vendorPartNum As String
Dim VendorID As Long
Dim ctr As Long
Dim xlLine As Integer
Dim allBlank As Integer
Dim insQry As String
Dim strFilter As String
Dim StrInputFileName As String
Dim xlApp As Excel.Application
Dim wkb As Excel.workbook
Dim wks As Excel.Worksheet
strFilter = ahtAddFilterItem(strFilter, "Excel Files (*.xlsx)", "*.xlsx")
strFilter = ahtAddFilterItem(strFilter, "Excel 97-2003 Files (*.xls)", "*.xls")
strFilter = ahtAddFilterItem(strFilter, "all Files (*.*)", "*.*")
StrInputFileName = ahtCommonFileOpenSave( _
filter:=strFilter, _
OpenFile:=True, _
DialogTitle:="Choose an image file...", _
Flags:=ahtOFN_HIDEREADONLY)
If Len(StrInputFileName) > 0 Then
' Do nothing as a file was chosen MsgBox strInputFileName, vbOKOnly
Else
'No file chosen, or user canceled
Exit Sub
End If
Set xlApp = CreateObject("Excel.application")
Set wkb = GetObject(StrInputFileName)
Set wks = wkb.Worksheets("Sheet1")
allBlank = 0
xlLine = 2
ctr = 0
Do While allBlank <= 3
partNum = wks.Cells(xlLine, "A")
If partNum = "" Or IsNull(partNum) Then
allBlank = allBlank + 1
xlLine = xlLine + 1
Else
allBlank = 0
desc = Replace(wks.Cells(xlLine, "F"), "'", "''")
Material = wks.Cells(xlLine, "I")
cost = wks.Cells(xlLine, "K")
vendorPartNum = wks.Cells(xlLine, "D")
VendorID = 43
insQry = "INSERT INTO TblParts([PartNumber],[PartDescription],[Material],[PartCost],[VendorPart],[VendorID]) " _
& "VALUES('" & partNum & "','" & desc & "','" & Material & "'," & cost & ",'" & vendorPartNum & "'," & VendorID & ")"
DoCmd.SetWarnings False
DoCmd.RunSQL insQry
DoCmd.SetWarnings True
Debug.Print insQry
ctr = ctr + 1
xlLine = xlLine + 1
End If
Loop
MsgBox (ctr)
The issue is that it wont append the whole data. THe total data it needs to append is 174, but instead it only does 25. And there are some autonumber that jumps (i.e after 1011 then 1040)
I have checked using debug.print and it seems perfectly fine (I can see 174 records in Immediate Window), so my suspect is the docmd.runsql insQry...but what happen?anyone can help?
Thanks