D
Don
I am trying to get code to work that identifies error messages so I can
suppress certain messages. Using the following code, I get a Run-Time error
'91' Object variable or With block veriable not set. The offending line of
code is:
If Err.Number = 3022 And dbs.QueryDefs(strQuery).Type = dbQAppend Then
and entire code is as follows:
Private Sub Command8_Click()
Dim dbs As DAO.Database
Dim wrk As DAO.Workspace
Dim strSQL As String, strQuery As String, strMessage As String
strSQL = "UPDATE tblTimerDate SET LastTimerDate = " & _
Format(Date, "\#mm/dd/yyyy\#")
On Error GoTo Err_Handler
If Time() > #6:30:00 AM# Then
If DLookup("LastTimerDate", "tblTimerDate") < Date Then
Set wrk = DAO.DBEngine.Workspaces(0)
Set dbs = CurrentDb
' begin transaction
wrk.BeginTrans
' Appends Rx table to RX1 table "Adds new RX's to RX1 table"
strQuery = "1Append Rx to RX1 Query"
dbs.Execute strQuery ', dbFailOnError
' Append Patient table to Patients table "Adds new records"
strQuery = "2Append Patient to PatientsQuery"
dbs.Execute strQuery ', dbFailOnError
' Deletes records from Patients that are "GONE" over 1 year
strQuery = "3Delete >1 years From Patients qry"
dbs.Execute strQuery ', dbFailOnError
' Update Housing Units from Patient table to Patients table
strQuery = "4Update Housing from Patient to Patients"
dbs.Execute strQuery ', dbFailOnError
' Deletes records from RX1 that are "GONE" over 1 year
strQuery = "5RX1 Delete >1 years Query"
dbs.Execute strQuery ', dbFailOnError
' Update tblTimerDate table
strQuery = "embedded SQL to update tblTimerDate"
dbs.Execute strSQL ', dbFailOnError
' no error so commit transaction
wrk.CommitTrans
End If
End If
Exit_Here:
Exit Sub
Err_Handler:
If Err.Number = 3022 And dbs.QueryDefs(strQuery).Type = dbQAppend Then
dbs.Execute strQuery
Resume Next
Else
strMessage = Error & " (" & Err.Number & ")" & vbNewLine & vbNewLine
& _
"(Error in " & strQuery & ")" & _
vbNewLine & vbNewLine & "Transaction rolled back and no tables
updated."
MsgBox strMessage, vbExclamation, "Error"
wrk.Rollback
End If
Resume Exit_Here
End Sub
I think I should Set strQuery to something but not sure what?
Thanks,
Dennis
suppress certain messages. Using the following code, I get a Run-Time error
'91' Object variable or With block veriable not set. The offending line of
code is:
If Err.Number = 3022 And dbs.QueryDefs(strQuery).Type = dbQAppend Then
and entire code is as follows:
Private Sub Command8_Click()
Dim dbs As DAO.Database
Dim wrk As DAO.Workspace
Dim strSQL As String, strQuery As String, strMessage As String
strSQL = "UPDATE tblTimerDate SET LastTimerDate = " & _
Format(Date, "\#mm/dd/yyyy\#")
On Error GoTo Err_Handler
If Time() > #6:30:00 AM# Then
If DLookup("LastTimerDate", "tblTimerDate") < Date Then
Set wrk = DAO.DBEngine.Workspaces(0)
Set dbs = CurrentDb
' begin transaction
wrk.BeginTrans
' Appends Rx table to RX1 table "Adds new RX's to RX1 table"
strQuery = "1Append Rx to RX1 Query"
dbs.Execute strQuery ', dbFailOnError
' Append Patient table to Patients table "Adds new records"
strQuery = "2Append Patient to PatientsQuery"
dbs.Execute strQuery ', dbFailOnError
' Deletes records from Patients that are "GONE" over 1 year
strQuery = "3Delete >1 years From Patients qry"
dbs.Execute strQuery ', dbFailOnError
' Update Housing Units from Patient table to Patients table
strQuery = "4Update Housing from Patient to Patients"
dbs.Execute strQuery ', dbFailOnError
' Deletes records from RX1 that are "GONE" over 1 year
strQuery = "5RX1 Delete >1 years Query"
dbs.Execute strQuery ', dbFailOnError
' Update tblTimerDate table
strQuery = "embedded SQL to update tblTimerDate"
dbs.Execute strSQL ', dbFailOnError
' no error so commit transaction
wrk.CommitTrans
End If
End If
Exit_Here:
Exit Sub
Err_Handler:
If Err.Number = 3022 And dbs.QueryDefs(strQuery).Type = dbQAppend Then
dbs.Execute strQuery
Resume Next
Else
strMessage = Error & " (" & Err.Number & ")" & vbNewLine & vbNewLine
& _
"(Error in " & strQuery & ")" & _
vbNewLine & vbNewLine & "Transaction rolled back and no tables
updated."
MsgBox strMessage, vbExclamation, "Error"
wrk.Rollback
End If
Resume Exit_Here
End Sub
I think I should Set strQuery to something but not sure what?
Thanks,
Dennis