[AccessD] ADO recordsets and connection objects - solution

Bud Goss bgoss711 at ameritech.net
Fri Mar 10 17:22:19 CST 2006


Thanks to all who replied to my post.
   
  Using the information you provided and hacking around a bit I finally was able to limp into first base on this effort.  Next week I will have to try to continue and try to steal ADO second base.
   
  The code that actually worked using the udl file is: 
  ( found that I do not have to reference “Microsoft PLE DB Service Component 1.0)
   
    
  Public Sub MyADOTestAA()
  Dim oCnn As ADODB.Connection
  Dim sFileNamePath As String
  Dim rs As ADODB.Recordset
  Dim strProvider As String
   
  Set rs = New ADODB.Recordset
  Set oCnn = New ADODB.Connection
   
  sFileNamePath = "File Name=c:\B\A\X.udl"
  oCnn.ConnectionString = "Provider = 'Microsoft.Jet.OLEDB.4.0';" & " Persist Security Info= 'False';"
   
  oCnn.Open sFileNamePath
      
      rs.Open "Select * from [Products] ", oCnn
      rs.MoveFirst
      MsgBox "=> " & rs(0) & " - " & rs(1) & " - " & rs(2)
      rs.Close
      Set rs = Nothing
      Set oCnn = Nothing
   
  End Sub 
   
  *** Original Post ***
   

I am trying to learn the basics of ADO recordsets and connections.

  So far, I have been unable to get to first base. The two methods 

listed below give me the following error:

   

  

  Run-time error'-2147467259(80004005)

  [Microsoft][ODBC Driver Manager] Data source name not found and no

  default driver specified   

  First attempt with udl file:   

  Public Sub MyADOTest01()

  Dim rec As ADODB.Recordset

  Set rec = New ADODB.Recordset

  rec.Open "Select * from [Orders] ", "File Name = C:\B\A\x.udl"

  rec.CursorLocation = adUseClient

  rec.LockType = adlockBatchOptimistic

  MsgBox "OPEN HAS OCCURED " & rec!Customer

  End Sub

  Second attempt without udl file”

   

  Public Sub MyADOTest02()

  Dim rec As ADODB.Recordset

  Set rec = New ADODB.Recordset

  rec.Open "Select * from [Orders]", "File Name = C:\B\A\Northwind.mdb"

  rec.CursorLocation = adUseClient

  rec.LockType = adlockBatchOptimistic

  MsgBox "OPEN HAS OCCURED " & rec!Customer

  rec.activeconnection.Close

  End Sub   

  C:\B\A\     
. Contains    x.udl   and  Northwind.mdb

  x.udl points to C:\B\A\Northwind.mdb and has MicrosoftJet 4.0 OLE 

Provider specified   

  Subs are contained in another Access 2003 database that is located in 

C:\B\A_Access_Tr   

  This database does have the  reference 

  Microsoft ActiveX data Objects 2.1 Llibrary  

    

  Any help would be appreciated.
   



More information about the AccessD mailing list