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
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
This might help also:
Dim rs 'As DAO.RecordSet
Set rs=CurrentDB.OpenRecordSet ("Table1")
Mike
Dim rs 'As DAO.RecordSet
Set rs=CurrentDB.OpenRecordSet
Mike
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(SQ L_Str)
Kind regards,
Sven
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.
Kind regards,
Sven
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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.
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!
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!
wsteegmans: Please post on question
https://www.experts-exchange.com/questions/20804511/Attention-Experts-MSAccess-TOP-15-Challenge-for-November-2003.html
https://www.experts-exchange.com/questions/20804511/Attention-Experts-MSAccess-TOP-15-Challenge-for-November-2003.html
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- --
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
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- -------
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
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
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
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.
Thanx Andrew, you're right on this one.
DIM dbs 'AS Database
or
DIM dbs AS DAO.Database