Compile Error in VBA

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DThreadgill
    New Member
    • Aug 2007
    • 57

    Compile Error in VBA

    I have a database that was designed in Access 2002 and has been working perfectly. I was switched to a new pc that has Access 2003 and now I'm getting an error message: "Compile Error: Method or data member not found."

    Code:
    Dim rs As Recordset
    Dim rst As Recordset
    Dim sql As String
    Dim str As String
    Dim strqry As String
    Dim icount As Integer
    
    str = "SELECT [CRISSRef], [Comments1], [Date], [Time]" & _
        "FROM tblComments ORDER BY [CRISSRef], [Date], [Time]"
    Set rst = CurrentDb.OpenRecordset(str)
    
    While Not rst.EOF
    sql = "Select * from [tcomments] where  [crissref]=" & rst(0) & " order by [crissref]"
    
    Set rs = CurrentDb.OpenRecordset(sql)
    
    rs.Edit            <----------------------Code fails here and .Edit is highlighted
    If IsNull(rs(1)) Then
    rs(1) = Left(rst(1), 255)
    there's more code but I think this may give the gist of it....

    I have references to MS Access 11.0 Object Library, MS ActiveX Data Objects Library 2.8. Is it the new version of Access or am I missing a reference?

    Thanks for your help!
  • Stewart Ross
    Recognized Expert Moderator Specialist
    • Feb 2008
    • 2545

    #2
    Hi. You are indeed missing a reference, to the Microsoft DAO object library. You will also need to qualify your recordset declarations to refer to the DAO (Data Access Objects) version explicitly. The problem arises because recordset objects are available in different types - ADOX, DAO, whatever. These have differing method statements and properties... a darn nuisance when moving from one version of Access to another.

    Anyway, if you add the latest Microsoft DAO x.x Object Library to your references and change the DIM to
    [code=vb]Dim rst As DAO.Recordset[/code]all should work again.

    -Stewart

    Comment

    • DThreadgill
      New Member
      • Aug 2007
      • 57

      #3
      That worked!! Thank you so much!!!!!

      Comment

      Working...