Dim db As Database returns error User-defined type not defined

mik

Lost in a VBA Jungle
Local time
Today, 14:36
Joined
Nov 16, 2004
Messages
22
Hi, I am trying to return a value from an SQL to VB and the examples tell me to either use Dim db As DAO.Database or Dim db As Database, neither of which work in my Access 2002 machine

The explicit error message I get for 'Dim db As Database returns ' is 'error User-defined type not defined'

I read about setting DAO thru Tools / References, but References is not highlighted.

Any suggestions.
 
Search in the FAQ forum for the A97 to A2002 DAO to ADO thread.
 
Stop execution of code running and References should be available. The error is caused by missing DAO library.
 
Thanks for your help, I have managed to activate Microsoft DAO 3.6 and are getting much closer. Using the following query as a test, I have one more bug to iron out.

Private Sub Test_DAO_Click()
Dim dbs As Database
Dim rst As Recordset
Dim Sql_Str As String

Set dbs = CurrentDb
Sql_Str = "Select Country From carrier"
Set rst = dbs.OpenRecordset(Sql_Str)
MsgBox rst.RecordCount

End Sub

"Run Time Error '13': Type Mismatch" on line "Set rst = dbs.OpenRecordset(Sql_Str)"
 
Last edited:
Dim dbs As DAO.Database
Dim rst As DAO.Recordset


since both ADO and DAO have a Recordset object.
.
 
DAO must be stated

Thanks Jon, have put the DAO in and now it works.

An explanation for this is on Microsofts web site
http://support.microsoft.com/?kbid=181542

Query returns 1 if data is present in the query and 0 if it isn't which does the trick for what I want to do.

Does anyone have a list of actions I could do, for example return the actual value selected?
 

Users who are viewing this thread

Back
Top Bottom