Solved

ADO - DAO -CurrentDb

Posted on 2000-02-27
13
1,621 Views
Last Modified: 2012-05-11
Hi

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
DAO.

Is there in ADO something like DAO's
CurrentDb()?

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
ADODB.recordset?

Boel
0
Comment
Question by:boel
  • 4
  • 4
  • 4
  • +1
13 Comments
 
LVL 44

Expert Comment

by:bruintje
ID: 2562364
Hi boel,

This sample will get you started

http://support.microsoft.com/support/kb/articles/Q167/9/57.ASP

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

HTH:O)Bruintje
0
 
LVL 44

Expert Comment

by:bruintje
ID: 2562370
or a quick look

http://msdn.microsoft.com/library/periodic/period98/vb0498.htm

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

http://msdn.microsoft.com/vbasic/technical/tutorial/tour/default.asp

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

http://msdn.microsoft.com/vbasic/technical/tutorial/tour/data.asp


HTH:O)Bruintje
0
 
LVL 1

Expert Comment

by:Phoat
ID: 2562467
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
0
 

Author Comment

by:boel
ID: 2562636
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..?

Boel
0
 
LVL 1

Expert Comment

by:spruce22
ID: 2562712
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

"DSN=AdoDemo;UID=admin;PWD=;"

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.








0
 
LVL 44

Expert Comment

by:bruintje
ID: 2562720
that is what was given in the first article already.....
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 1

Expert Comment

by:spruce22
ID: 2562793

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.

spruce22
0
 
LVL 44

Expert Comment

by:bruintje
ID: 2562808
yep i know, just to tired, already eyeing the hay :O)

Good Luck!
0
 

Author Comment

by:boel
ID: 2562924
To Spruce22:
Isn't there some "easy" way to make the connectionString to point to the default
database?

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.



0
 
LVL 1

Accepted Solution

by:
spruce22 earned 200 total points
ID: 2562938
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

?currentdb.Name

Then you could insert this value into your connection string.

Is this what you're looking for?
0
 

Author Comment

by:boel
ID: 2563036
Yes thats what I'm looking for.
Thank you.
0
 
LVL 1

Expert Comment

by:spruce22
ID: 2563044
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.
0
 

Author Comment

by:boel
ID: 2565741
Well, I make a total og everything,
have you giving me the correct answer directly then I will have give you A.

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

948 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now