R
rich575
The code below produces a "Compile error: User-defined type not defined."
error message.
When the execution stops, "dbs As DAO.Database" is highlighted.
What is the problem and solution? Thanks for your help.
Richard
Code:
Function SetItemCodes()
Call SetUniqueCodes
End Function
Private Sub SetUniqueCodes()
Dim dbs As DAO.Database
Dim lngNextNum As Long, lngOrderID As Long
Dim rst As DAO.Recordset
Dim strSQL As String
strSQL = "SELECT OrderID, ItemID FROM ORDERITEM"
strSQL = strSQL & "ORDER BY OrderID;"
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(strSQL, dbOpenDynaset)
If rst.EOF = False And rst.BOF = False Then
rst.MoveFirst
lngOrderID = rst.Fields("OrderID").Value
lngNextNum = 0
Do While rst.EOF = False
If lngOrderID <> rst.Fields("OrderID").Value Then
lngNextNum = 0
lngOrderID = rst.Fields("OrderID").Value
End If
lngNextNum = lngNextNum + 1
rst.Edit
rst.Fields("ItemID").Value = lngNextNum
rst.Update
rst.MoveNext
Loop
End If
rst.Close
Set rst = Nothing
dbs.Close
Set dbs = Nothing
End Sub
error message.
When the execution stops, "dbs As DAO.Database" is highlighted.
What is the problem and solution? Thanks for your help.
Richard
Code:
Function SetItemCodes()
Call SetUniqueCodes
End Function
Private Sub SetUniqueCodes()
Dim dbs As DAO.Database
Dim lngNextNum As Long, lngOrderID As Long
Dim rst As DAO.Recordset
Dim strSQL As String
strSQL = "SELECT OrderID, ItemID FROM ORDERITEM"
strSQL = strSQL & "ORDER BY OrderID;"
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(strSQL, dbOpenDynaset)
If rst.EOF = False And rst.BOF = False Then
rst.MoveFirst
lngOrderID = rst.Fields("OrderID").Value
lngNextNum = 0
Do While rst.EOF = False
If lngOrderID <> rst.Fields("OrderID").Value Then
lngNextNum = 0
lngOrderID = rst.Fields("OrderID").Value
End If
lngNextNum = lngNextNum + 1
rst.Edit
rst.Fields("ItemID").Value = lngNextNum
rst.Update
rst.MoveNext
Loop
End If
rst.Close
Set rst = Nothing
dbs.Close
Set dbs = Nothing
End Sub