Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Other Forums
 MS Access
 conversion of DAO "Set dbs = CodeDb" to ADO

Author  Topic 

jean
Starting Member

6 Posts

Posted - 2003-04-10 : 13:39:00
hi guys, what is the equivalent MS Access ADO (ActiveX Data Objects) code below

Set dbs = CodeDb?


thanks,
jean


jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2003-04-10 : 13:45:16
CodeDB is property of the Access application object that returns a pointer to a DAO database; it doesn't really apply to ADO. You would need to convert that reference to an equivalent ADO database and go from there.

Actually, I'm not sure how Access 2000 and above handles the CodeDB object ... does it return an ADO database reference? I am stuck with 97 while here at work... I ask this because DAO is not part of Access any more with versions 2000 and up so if that property still exists, it would return an ADO object reference I would think.

- Jeff
Go to Top of Page

rrb
SQLTeam Poet Laureate

1479 Posts

Posted - 2003-04-10 : 20:04:22
Yep, it's a little bit different

Firstly in ADO you open a connection. The connection points to both the server (or machine with the mdb on it) and the database within that server - which of course is superfluous for Access.

Why not just include the DAO library in your code? Then you can keep coding the way you're used to ....?

Anyway here's some example code


Dim Cnxn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim strSQL As String

'Open a new connection to the database
Set Cnxn = CreateObject("ADODB.Connection")
Cnxn.Provider = "Driver={Microsoft Access Driver (*.mdb)};" & _
"Dbq=c:\somepath\mydb.mdb;" & _
"Uid=admin;" & _
"Pwd="
Cnxn.Open
Set rst = CreateObject("ADODB.Recordset")
strSQL = "select * from table"
rst.Open strSQL, Cnxn
Do While Not rst.EOF
Debug.Print rst.FIelds(0)
rst.moveNext
Loop
rst.Close

Set rst = Nothing
Set Cnxn = Nothing

Ask more questions....


PS - you might want to take a look at [url]http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B210314[/url]

Cheers
--
I hope that when I die someone will say of me "That guy sure owed me a lot of money"

Edited by - rrb on 04/10/2003 20:14:38
Go to Top of Page
   

- Advertisement -