Solved

ADO - DAO -CurrentDb

Posted on 2000-02-27
13
1,617 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

758 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

21 Experts available now in Live!

Get 1:1 Help Now