Results 1 to 4 of 4
  1. #1
    sanderson is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    64

    Insanity with Runtime Error 3219

    Hello:

    Here is my code, which worked fine a few hours ago, and I have made no changes to this part of the program...

    All the way at the bottom is rs.close. This happened once before, and it just started magically working the next day. Maybe I will get lucky in the morning. Anyhow, the rs.close produces the error 3219 - Operation not allowed in this context. When I remove, the error goes away but the program does not execute.

    Thank you.


    Code:
    Private Sub cmdSubmitTimeCard_Click()
        Dim rs As adodb.recordset
        Set rs = New adodb.recordset
    
    
        Dim sql As String
       
        sql = "SELECT * FROM tblocalApprovalLog "
        sql = sql & "WHERE (empid = '" & empid & "' OR supid = '" & Forms!frmTimeCard.txtEmpID.Value & "') "
        sql = sql & "AND approve = True "
        sql = sql & "AND approved = False "
        sql = sql & "AND dayDate = '" & Forms!frmTimeCard.txtDate.Value & "' "
        sql = sql & "AND weekDate = '" & Forms!frmTimeCard.txtPeriodStart.Value & " - " & Forms!frmTimeCard.txtPeriodEnd.Value & "' "
        sql = sql & "AND shortchar02 = 'Salaried'"
    
    
        Debug.Print ("sql: " & sql)
          
        rs.Open sql, CurrentProject.Connection, adOpenDynamic, adLockOptimistic
        On Error GoTo endloop
    
    
        Dim c As Integer
        c = 0
            
        Do While Not rs.BOF Or rs.EOF
            c = c + 1
            Debug.Print ("RecordCount: " & CStr(c))
    
    
            ' On Error GoTo endloop
            txtEmpID = rs.Fields("empid")
            rs.Fields("approved") = True
                                
            ' Send EMail
            GenerateEmailContent_Weekly (txtEmpID)
            Debug.Print ("Email # " & c & " has been sent.")
                
            rs.MoveNext
            
        Loop
    
    
    endloop:
        Me.Requery
        rs.Close
        Set rs = Nothing
    
    
    End Sub


  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    If there are not any records retrieved with .Open you will not be able to .Close. At least that is how it is with DAO. I usually check that recordcount is greater than zero directly after.Open and exit sub if not.

  3. #3
    sanderson is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    64
    This is the query produced, and it does produce data!
    Code:
    SELECT * FROM tblocalApprovalLog WHERE (empid = '2255' OR supid = '2261') AND approve = True AND approved = False AND dayDate = '11/6/2015' AND weekDate = '11/2/2015 - 11/8/2015' AND shortchar02 = 'Salaried'
    Is there a better way to check for recordset validity than the way I'm doing it? Perhaps the rs.EOF or rs.BOF is not good??

    Thanks!

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Anytime you use a WHERE clause within a query, there will be a chance that zero records will be retrieved. I do not have all of the nuances of ADO memorized. I am not certain what the best approach is for determining a valid recordset. Over the years, while using DAO, I have used different approaches and, now, use something like the following ...
    Code:
    If rs.Recordcount < 1 then
    Set rs = Nothing
    exit sub
    end if
    I do this because a Dynaset or Snapshot in DAO will always retrieve at least one record from a valid recordset, even without Movelast. I do not believe this to be much different than testing for both EOF and BOF. The takeaway should be that if you do not have any records, if you are on EOF or BOF, set the rs to Nothing and exit the procedure without trying to .Close an invalid recordset that is not in an Open state.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 08-22-2015, 11:26 AM
  2. Dcount of Query in VBA gives Error 3219
    By krausr79 in forum Access
    Replies: 2
    Last Post: 10-20-2014, 12:00 PM
  3. Replies: 2
    Last Post: 10-15-2014, 04:23 AM
  4. Replies: 13
    Last Post: 06-12-2012, 09:52 PM
  5. runtime error 3219
    By Rider570 in forum Programming
    Replies: 3
    Last Post: 07-07-2010, 09:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums