Solved

ADO connection

Posted on 2002-04-30
5
494 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 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: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

776 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