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