Solved

ADO connection

Posted on 2002-04-30
5
528 Views
Last Modified: 2006-11-17
This is the first time I am using ADO. Could someone give some sample code to connect to a SQL database? I have a linked table to the sql db and a query to lookup some information from that table. I have done this using DAO (see below), but the sql database is asking for username and password that I do not want the users to see.
Thanks in advance,
Jim


Dim medrec As String
Dim db As DAO.Database
Dim rst As DAO.Recordset

Set db = CurrentDb()
Set rst = db.OpenRecordset("qry lookup", dbOpenSnapshot, dbReadOnly)
0
Comment
Question by:jmrasmus
[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
  • 3
  • 2
5 Comments
 
LVL 5

Accepted Solution

by:
KMAN earned 100 total points
ID: 6981708
Here is sample code to connect using ADO to any ODBC datasource.

Dim myCn As New ADODB.Connection
Dim myRs As New ADODB.Recordset
   
myCn.ConnectionString = "DSN=myDataSource"
myCn.Open
myRs.Open "SELECT * FROM myTable", myCn, adOpenDynamic

Good Luck!

K
0
 
LVL 5

Expert Comment

by:KMAN
ID: 6981727
Don't forget to add "Microsoft ActiveX Data Objects..." reference to your app.
0
 

Author Comment

by:jmrasmus
ID: 6981798
Kman,
does the myrs recordset have the same properties as the DAO recordset? By that I mean using DAO I can loop through the rescordset, do compairisons to a particular field ie myrs.Fields("Last Name").value="Jones".
Thanks
Jim
0
 
LVL 5

Expert Comment

by:KMAN
ID: 6981825
Very similar to DAO and many of the same properties are available, and some new ones added.

K
0
 

Author Comment

by:jmrasmus
ID: 6982081
Thanks loads!!!!!
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
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…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

622 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