DAO.Database - User-defined type not defined?

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
 
D

Dave Patrick

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
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top