Good day. All.
I have a recordset that I pull values from.
like
myValue = rst.fields("Field1")
I loop through the recordset and sometimes
the field is empty (I think) and it throws an error.
"Invalid use of null!"
Since I need to obviously keep running the program instead of crashing, how can I trap this event?
I'm building Insert queries with the results like
Insert into myTable values(myValue.myValue2, myValue3)
and using Docmd.runSQL
This builds the entries in a new table. For those interested,I'll put some code below.
Thanks everyone.
PB
Do While Not rst2.EOF
myVendorNum = rst2.Fields("Code")
Set qdf = dbs.QueryDefs!ToolUseExport
qdf.Parameters![Enter Vendor Code (5 digits):] = CLng( myVendorNum)
Set rst = qdf.OpenRecordset
rst.MoveLast
rst.MoveFirst
myCount = rst.RecordCount
myVendor = rst.Fields("Vendor")
myName = rst.Fields("Name")
Do While Not rst.EOF
myPrefix = rst.Fields("Prefix")
myItem = rst.Fields("ItemNum")
myDesc = rst.Fields("Description")
myPos = InStr(1, myDesc, "'")
Do While myPos <> 0
myFirstPart = Left(myDesc, myPos - 1)
myStart = myPos + 1
myLen = Len(myDesc)
mySecondstart = myLen - myStart
mySecondpart = Right(myDesc, mySecondstart)
myDesc = myFirstPart & mySecondpart
myPos = InStr(1, myDesc, "'")
Loop
myComCode = rst.Fields("CommodityCode")
myLot = rst.Fields("OrderLot")
myLead = rst.Fields("LeadTime")
myDateStr = rst.Fields("LASTISSUED")
myModel = rst.Fields("ModelNum")<-Crashes on 13th pass
myUse = rst.Fields("90DayUse")
myDate = CDate(myDateStr)
mySQL = "INSERT INTO ToolTemp VALUES (" & myVendor
& ",'" & myName & "','" & myPrefix & "','" & myItem & "','" & myDesc & "','" & myModel & "','" & myComCode & "'," & myLot & "," & myLead & ",#" & myDate & "#," & myUse & ")"
Debug.Print mySQL
DoCmd.RunSQL mySQL
rst.MoveNext
Loop
I have a recordset that I pull values from.
like
myValue = rst.fields("Field1")
I loop through the recordset and sometimes
the field is empty (I think) and it throws an error.
"Invalid use of null!"
Since I need to obviously keep running the program instead of crashing, how can I trap this event?
I'm building Insert queries with the results like
Insert into myTable values(myValue.myValue2, myValue3)
and using Docmd.runSQL
This builds the entries in a new table. For those interested,I'll put some code below.
Thanks everyone.
PB
Do While Not rst2.EOF
myVendorNum = rst2.Fields("Code")
Set qdf = dbs.QueryDefs!ToolUseExport
qdf.Parameters![Enter Vendor Code (5 digits):] = CLng( myVendorNum)
Set rst = qdf.OpenRecordset
rst.MoveLast
rst.MoveFirst
myCount = rst.RecordCount
myVendor = rst.Fields("Vendor")
myName = rst.Fields("Name")
Do While Not rst.EOF
myPrefix = rst.Fields("Prefix")
myItem = rst.Fields("ItemNum")
myDesc = rst.Fields("Description")
myPos = InStr(1, myDesc, "'")
Do While myPos <> 0
myFirstPart = Left(myDesc, myPos - 1)
myStart = myPos + 1
myLen = Len(myDesc)
mySecondstart = myLen - myStart
mySecondpart = Right(myDesc, mySecondstart)
myDesc = myFirstPart & mySecondpart
myPos = InStr(1, myDesc, "'")
Loop
myComCode = rst.Fields("CommodityCode")
myLot = rst.Fields("OrderLot")
myLead = rst.Fields("LeadTime")
myDateStr = rst.Fields("LASTISSUED")
myModel = rst.Fields("ModelNum")<-Crashes on 13th pass
myUse = rst.Fields("90DayUse")
myDate = CDate(myDateStr)
mySQL = "INSERT INTO ToolTemp VALUES (" & myVendor
& ",'" & myName & "','" & myPrefix & "','" & myItem & "','" & myDesc & "','" & myModel & "','" & myComCode & "'," & myLot & "," & myLead & ",#" & myDate & "#," & myUse & ")"
Debug.Print mySQL
DoCmd.RunSQL mySQL
rst.MoveNext
Loop