Dim db As Database returns error User-defined type not defined (1 Viewer)

mik

Lost in a VBA Jungle
Local time
Tomorrow, 06:24
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.
 

Mile-O

Back once again...
Local time
Today, 21:24
Joined
Dec 10, 2002
Messages
11,316
Search in the FAQ forum for the A97 to A2002 DAO to ADO thread.
 

geralf

Registered User.
Local time
Today, 21:24
Joined
Nov 15, 2002
Messages
212
Stop execution of code running and References should be available. The error is caused by missing DAO library.
 

mik

Lost in a VBA Jungle
Local time
Tomorrow, 06:24
Joined
Nov 16, 2004
Messages
22
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:

Jon K

Registered User.
Local time
Today, 21:24
Joined
May 22, 2002
Messages
2,209
Dim dbs As DAO.Database
Dim rst As DAO.Recordset


since both ADO and DAO have a Recordset object.
.
 

mik

Lost in a VBA Jungle
Local time
Tomorrow, 06:24
Joined
Nov 16, 2004
Messages
22
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

Top Bottom