Link to home
Start Free TrialLog in
Avatar of steveRosenberg
steveRosenberg

asked on

Can't define database object in code

Hi:

     When I attempt to create a database object like this:

        DIM dbs AS Database

    and run the code I get the message "User defined-type not defined".  In fact, when I type to the "AS" the pop-up dropdown menu that appears does not even contain "Database" as a choice.  I have to be able to define a database object so I can do SELECT queries.  Can anyone tell me why I can't define this object?.  Thanks.

Steve
Avatar of Mike Eghtebas
Mike Eghtebas
Flag of United States of America image

try:

DIM dbs 'AS Database

or

DIM dbs AS DAO.Database
This might help also:

Dim rs 'As DAO.RecordSet
Set rs=CurrentDB.OpenRecordSet("Table1")

Mike
Avatar of svenkarlsen
svenkarlsen

Hi steveRosenberg,

Egtebas has provided you with the correct answer.

If you want to run a query under ADO, you may use the syntax:

StrVar = CurrentProject.Connection.Execute(SQL_Str)



Kind regards,
Sven
ASKER CERTIFIED SOLUTION
Avatar of wsteegmans
wsteegmans

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Once you have selected the DAO reference to make it the default you need to promote the DAO Reference to above all other references that have the say object types, ei ADO.

If you want DAO as you default make it 3rd in the list then you do not need to declare it with the DAO. in front.

Cheers, Andrew
Dim dbs as dao.database

set dbs = CurrentDb

then you can use it...

remember

set dbs = nothing

at the end of your code.
TextReport is right, however there won't be a problem declaring your database (ADO hasn't such a Database Class).

Maybe, you can even better remove the Microsoft ActiveX Data Objects Library, if you just want to use DAO.

Event better, use always in your declarations the library ... This means, use
'DIM dbs AS DAO.Database' instead of 'DIM dbs AS Database'.
So, you know perfectly what you're doing, and it works always (no matter what the priority of your references is).

Regards!
Avatar of jadedata
----------------------------------------------------------------------------------------
This question has been abandoned and needs to be finalized.
 You can accept an answer, split the points, or get a refund (information at http:/help.jsp#hs5)
  If you need a moderator to help you, post a question at Community Support (http:/Community_Support/)

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

ornicar
Cleanup Volunteer

---------------------------------------------------------------------------------------------
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: eghtebas {http:#9840472}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jadedata
EE Cleanup Volunteer
Jack, I would suggest that wsteegmans had the correct answer as the answer provided didn't just "get round" the issue but also explained it.

Cheers, Andrew
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: wsteegmans {http:#9840644}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jadedata
EE Cleanup Volunteer
Recommendation changed on re-read.  
Thanx Andrew, you're right on this one.