DAO.Database - User-defined type not defined?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
From any module Tools|References and make sure you have DAO 3.6 checked.

--

Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect

:
| 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
|
 
Back
Top