Access97 + ADO 
Author Message
 Access97 + ADO

I need to be able to use ADO within a Access 97 module, but i don't know who
to do this. Can anybody help? All I want is to open a connection, and then
do a select. Can anybody supply some sample code?

I thought somthing like the following would be correct. But obviously not.

Dim ex1 as Object, ex2 as Object
Set Exl = CreateObject("ADODB.Connection")
Set ex2 = CreateObject("ADODB.RecordSet")
ex1.Open "DSN=dsname;UID=username;DATABASE=dbname;Trusted_Connection=Yes"
ex2= ex1.Execute("select * from tbldevDocuments")
ex2.MoveNext
ex1.Close



Mon, 06 Jan 2003 03:00:00 GMT  
 Access97 + ADO

Neil,

Something like the following code usually works for me.  You would need an
appropriate provider to be installed on your machine (I believe they come
with MDAKs), and Microsoft ActiveX Data Objects to be included in references
to your project (Tools-References, when in Module Design view)

Sub ADOtest()
Dim con As ADODB.Connection ' or you can use "New" here, then you would not
need to Set
Dim rs As ADODB.Recordset ' same for this one

Set con = New ADODB.Connection
con.ConnectionString = "Provider=SQLOLEDB;Password=password;User
ID=userlogin;" & _
                                    "Persist Security Info=True;Data
Source=servername;Initial Catalog=dbname"
' SQLOLEDB is provider for SQL server, and other providers are:
'
' MSDASQL for ODBC, in this case string looks like this:
' "Provider=MSDASQL;Driver={SQL Server};SERVER=server;" & _
' "DATABASE=database;UID=userlogin;PWD=password;"
'
' Microsoft.Jet.OLEDB.4.0 (for Jet 4.0), string like this:
' Provider=Microsoft.Jet.OLEDB.4.0;" & _
'      "Data Source=database path and name;" & _
'      "Jet OLEDB:Database Password=password;"
'
'
 con.Open
Set rs = New ADODB.Recordset
rs.Open "table name/SQL statement", con, adOpenForwardOnly, adLockReadOnly '
or other settings
With rs
    Do While Not .EOF
        Debug.Print ![field name] ' or whatever you want to do with a record
        .MoveNext
    Loop
    .Close
End With
Set rs = Nothing
con.Close
Set con = Nothing
End Sub

Hope this helps.

Alex


Quote:
> I need to be able to use ADO within a Access 97 module, but i don't know
who
> to do this. Can anybody help? All I want is to open a connection, and then
> do a select. Can anybody supply some sample code?

> I thought somthing like the following would be correct. But obviously not.

> Dim ex1 as Object, ex2 as Object
> Set Exl = CreateObject("ADODB.Connection")
> Set ex2 = CreateObject("ADODB.RecordSet")
> ex1.Open "DSN=dsname;UID=username;DATABASE=dbname;Trusted_Connection=Yes"
> ex2= ex1.Execute("select * from tbldevDocuments")
> ex2.MoveNext
> ex1.Close



Mon, 06 Jan 2003 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. VB6,Access97,ADO - Update query doesn't update all records

2. DHTML, Access97, ADO and VB Scripting

3. Access97 ADO SQL7 transactions - undefined recordset after COMMIT

4. ADO VB6 Access97 Unable to run Access Query -2147217900

5. VB6/ADO/Access97 Security

6. Access97 and ADO

7. ADO and Access97

8. ado access97

9. ADO VB6 Access97 Unable to run Access Query -2147217900

10. ADO 2.1/VBScript/Access97

11. Access97 and ADO

12. Seek method, Access97 database, ADO in VB6

 

 
Powered by phpBB® Forum Software