Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2002
    Location
    Island of Dots
    Posts
    316

    Unanswered: How to set Form.RecordSource from ADO rs

    I want to set a forms RecordSource to the results of an ADO record set. Here is my code:
    Code:
    Dim cnn As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    Dim sQry As String
    Dim strConnection As String
    
    strConnection = "Driver={Microsoft Access Driver (*.mdb)};" & _
    "Dbq=BackEnd.mdb;" & _
    "DefaultDir=C:\Documents and Settings\Cambord\My Documents\ADO Test\;" & _
    "Uid=Admin;Pwd=;"
    
    cnn.ConnectionString = strConnection
    cnn.Open
    'cnn.Close
    
    Set rs = New ADODB.Recordset
    rs.Open "tblEmployees", cnn, adOpenStatic, adLockReadOnly
    rs.MoveFirst
    
    Forms!frmEmployees.RecordSource = rs
    However, Access doesn't seem to like the last line. How can I do this?

  2. #2
    Join Date
    Jul 2002
    Location
    Island of Dots
    Posts
    316
    No matter, I think I know the answer... I think I will have to set each field individually, eg - txtEmpID = rs!EmpID, etc.

  3. #3
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Geez ... Set the RecordSource to the SQL query (or make one) and then Requery the form ... Since you're opening a table with your recordset just put something like: "SELECT * FROM tblEmployees;" in the RecordSource ...
    Back to Access ... ADO is not the way to go for speed ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •