open ADO via object create....

User avatar
sal21
PlatinumLounger
Posts: 4370
Joined: 26 Apr 2010, 17:36

open ADO via object create....

Post by sal21 »

Instead to set the ado reference in a vba project is possible to set ado connection via ...CreteObject ecc... similar a outllok binding mode?

Note:
In effect i dont know wich version of ado have all user tath use my application:-)

User avatar
HansV
Administrator
Posts: 78629
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: open ADO via object create....

Post by HansV »

You can use code like this:

Code: Select all

    Dim cnn As Object
    Dim rst As Object
    Dim strConnection As String
    Dim strSQL As String
    strConnection = "..."
    strSQL = "SELECT ..."
    Set cnn = CreateObject("ADODB.Connection")
    cnn.Open strConnection
    Set rst = CreateObject("ADODB.Recordset")
    rst.Open strSQL, cnn, 1, 3, 1
In the last line, the numbers 1, 3, 1 correspond to the ADODB constants adOpenKeyset, adLockOptimistic and adCmdText, respectively. You have to look up the values of these constants in the Object Browser in Access, or in another application where you have set a reference to ADO.
Best wishes,
Hans