Solved

ADO - DAO -CurrentDb

Posted on 2000-02-27
13
1,653 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

752 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