Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ADO connection

Posted on 2002-04-30
5
Medium Priority
?
541 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
  • 3
  • 2
5 Comments
 
LVL 5

Accepted Solution

by:
KMAN earned 400 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

[Webinar] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

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

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

916 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