Results 1 to 2 of 2

Thread: DAO.recordset

  1. #1
    Join Date
    Oct 2002
    Posts
    8

    Unanswered: DAO.recordset

    Hey there,
    I'm trying to open a table so that i can assign some values but i can't even set the variable type

    sub crap()
    refInfo As DAO.recordSet
    refInfo.Open "select * from [student information]", _ CurrentProject.Connection, asOpenKeyset, adLockOptimistic
    end sub

    i get a compile error "user-defined type not defined" for the refInfo as DAO.recordset line

    1) Why is DAO.recordSet not defined even though i see it in examples?
    2) Is this a good way to play with information in tables?
    3) Is there any good web site with information on this so that i don't have to bug people with silly 1,2,3 questions?

    thanks all

  2. #2
    Join Date
    Oct 2001
    Location
    Chicago
    Posts
    440
    You need to set a reference to DAO:
    Tools-->References
    select Microsoft DAO 3.XX Object Library

    Your code is a mix of ADO and DAO

    Search the Help for examples of recordsets and you'll get the picture.
    Or just use Google to search ADO Recordset and DAO Recordsets.

    Here's a DAO example:

    Sub DAO_Recordset()

    Dim dbs As DAO.Database
    Dim rst As DAO.Recordset
    Dim strSQL As String

    On Error GoTo ErrorHandler

    strSQL = "select * from [TableName]"

    Set dbs = CurrentDb()

    ' Open the recordset
    Set rst = dbs.OpenRecordset(strSQL, dbOpenDynaset)

    'move through the recordset to get an accurate count
    rst.MoveLast
    If rst.RecordCount > 0 Then
    rst.MoveFirst
    Do Until rst.EOF
    rst.Edit
    rst!FieldName = <New Value>
    rst.Update
    rst.MoveNext
    Loop
    End If

    'cleanup
    rst.Close
    Set rst = Nothing
    dbs.Close
    Set dbs = Nothing

    ErrorHandlerExit:
    Exit Sub

    ErrorHandler:
    MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
    Resume ErrorHandlerExit

    End Sub


    Matt

Posting Permissions

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