Private Sub UpdateSOMTRecord(ByVal recordID As Long, ByVal taskID As Long, completeFlag As Long)
Dim Conn1 As New ADODB.Connection
'Dim Rs1 As New ADODB.Recordset
Dim Rs2 As New ADODB.Recordset
Dim Errs1 As Errors
Dim AccessConnect As String, strExecute As String, strExecute2 As String
Dim strTmp As String
' Don't assume that we have a connection object.
On Error GoTo AdoError
'connect to the access database.
'DBQ = supply path of access db \\Server\...
AccessConnect = "Driver={Microsoft Access Driver (*.mdb)};" & _
"Dbq=C:\Temp\SOMT.mdb;" & _
"DefaultDir=;" & _
"Uid=;Pwd=;"
If completeFlag = -1 Then
strExecute = "UPDATE tblTasks SET Completed = " & completeFlag & _
", Status ='Closed', AFinish=PFinish WHERE RecordID = " & recordID & _
" AND TaskID = " & taskID
strExecute2 = "SELECT * FROM tblTasks WHERE RecordID = " & recordID & _
" AND Status ='Pending' AND EmailSent = False AND Completed = False Order By TaskID"
Rs2.LockType = adLockOptimistic
Conn1.Open AccessConnect
Conn1.Execute (strExecute)
'Set Rs1 = Conn1.Execute(strExecute)
Set Rs2 = Conn1.Execute(strExecute2)
MsgBox "Set RS2"
Rs2.MoveFirst
MsgBox "Moved RS2 to first"
If Rs2.BOF Then
'do nothing
Else
MsgBox "RS2 ELSE"
Rs2("Status").Value = "Active"
MsgBox "RS2 UPDATED"
End If
Else
strExecute = "UPDATE tblTasks SET Completed = " & completeFlag & _
", Status = 'Pending', AFinish=Null WHERE RecordID = " & recordID & _
" AND TaskID = " & taskID
Conn1.Open AccessConnect
Conn1.Execute (strExecute)
'Set Rs1 = Conn1.Execute(strExecute)
End If
Conn1.Close
Done:
' Set Rs1 = Nothing
Set Rs2 = Nothing
Set Conn1 = Nothing
Exit Sub
AdoError:
' Get VB Error Object's information
strTmp = strTmp & vbCrLf & "VB Error # " & Str(Err.Number)
strTmp = strTmp & vbCrLf & " Generated by " & Err.Source
strTmp = strTmp & vbCrLf & " Description " & Err.Description
MsgBox strTmp
GoTo Done
End Sub