Results 1 to 3 of 3

Thread: DAO Object invalid or no longer set

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2022
    Posts
    2

    Unhappy DAO Object invalid or no longer set

    This is such a simple basic thing I've done for decades yet now a problem? I'm sure it's something silly I'm missing. A search provides no answer for my situation.
    Library reference is to Microsoft Office 16.0 Access database engine object library. I removed that and changed it to DAO 3.6 library. Both compiled. Both gave me the same error.


    Code:
     Dim db As DAO.Database
        Dim rs As DAO.Recordset
    
        Set db = CurrentDb
        Set rs = db.OpenRecordset(strSQL)
       
        strElig = rs("Elig")  -- This works!
       
        Do Until rs.EOF  -- error occurs here! Grrrr!
       
            rs.movenext
        loop
    EOF is false before that value is accessed and assigned to the variable.
    After the value is assigned, the variable has the correct value "BS".
    I get a record count from the RS object before the error.
    I can movelast, movefirst.
    Only after it assigns this value do I get the error at "Do Until rs.eof".

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: DAO Object invalid or no longer set

    if you movefirst after editing the record, does the loop work?
    Last edited by westconn1; Apr 26th, 2022 at 05:21 AM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2022
    Posts
    2

    Re: DAO Object invalid or no longer set

    Right after I get the value from the record, the RS is invalid. I tried movefirst before accessing the value, it worked, but still got the error.

Posting Permissions

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



Click Here to Expand Forum to Full Width