• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1758
  • Last Modified:

ADO - DAO -CurrentDb


I have been using VB6 for a while and
have used ADO there with databases.
Now I'm looking at Access (97)
and I still want to use ADO and not

Is there in ADO something like DAO's

If I want to create a recordset in DAO I use something like this

Set db = CurrentDb()
Set rsDAO = db.OpenRecordset("transfers")

but if I try do do this on an "rsADO"
if want work.

How can I use CurrentDb() togheter with

  • 4
  • 4
  • 4
  • +1
1 Solution
Hi boel,

This sample will get you started


For ADO you have to use the connect and connectstring, then you can do what you want

or a quick look


and i knew i already played with it yesterday :O)


be sure to download all the stuff and then you can play with the data access sample which is pretty straightforwarded and hlping to understand it all


In ADO there is no database object like in DAO but rather there is a connection object.  You therefore have to make a connection to the database you're working on in order to access its recordsets.  This is done in the following way...

Dim cnn as ADODB.Connection
Set cnn = New ADODB.Connection

Then to open the connection, if the tables you want to work with are in the same database...

cnn.Open CurrentProject.Connection

You can then use the ADO recordset object to access your data.

rst.Open [tablename or SQL], cnn

cnn refers to the connection that you established earlier...

I don't know how well it works for Access97, but it works in Access2000
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

boelAuthor Commented:
Hi Phoat.

I know how to use the ADODB.Connetion
object togheter with ADODB.Recordset
but where thas CurrentProject.Connection
came from?

I don't think thats work in Access 97 or..?

CurrentProject.Connection is simply Access2000's default connection to a database when it's an Access Project(.adp).

The way you would use the ADO connection object in Access 97 is to provide your own connection string, and that string will have a different syntax based upon what type of database you're connecting to(Access DB, SQL Server, Oracle, etc...)  

An example connection string looks something like this


In this example The DSN=AdoDemo refers to the ODBC Datasource you wish to connect to, UID is the user to you wish to log in as, and PWD is the password you wish to use.  IF you're not famaliar with setting up ODBC data sources let me know and I can help.

You could then use ADO to connect to this datasource as shown below.

Sub Connect()

  dim strConnect as string
  Dim conn as ADODB.Connection

'Define connection information
  strConnect =  "DSN=AdoDemo;UID=admin;PWD=;"

'Create a new ADODB connection object
  Set conn = New ADODB.Connection

'Open the connection using the connection string
  conn.Open strConnect

End Sub

If you'd like more help with determening the particular connection string for the datasource you wish to connect to, let me know, otherwise hope this helps.

that is what was given in the first article already.....

The information was embedded somewhere within the first article, all I did was try to explain it in relation to boel's situation.  Your answer didn't get accepted(yet), but it was reviewed, so I posted again to see if my explanation could help boel.

yep i know, just to tired, already eyeing the hay :O)

Good Luck!
boelAuthor Commented:
To Spruce22:
Isn't there some "easy" way to make the connectionString to point to the default

I know how to set up a connectionString
directly to an Access(Jet) database but
I don't want to change the connectionString just because I change Access-project.

I'm not quite sure I understand.  Do you mean you want to connect to the database you're currently running?  If so, you can retrieve the path to the   database by using the CurrentDb.Name property.  This returns the path to the database you're currently running.

For example, from the debug window type


Then you could insert this value into your connection string.

Is this what you're looking for?
boelAuthor Commented:
Yes thats what I'm looking for.
Thank you.
No problem, glad to have helped.

Just for my info how could I have answered better (A instead of B).  I'm asking so I can do a better job in the future, as I'm new to this site.
boelAuthor Commented:
Well, I make a total og everything,
have you giving me the correct answer directly then I will have give you A.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

  • 4
  • 4
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now