Error trap this code

belsha

Registered User.
Local time
Today, 01:40
Joined
Jul 5, 2002
Messages
115
I have a cleanup procedure that checks a bunch of queries and prints the ones that meet the criteria. Each one looks like this:
'this code will print the cleanup routine for the Preop form
'*************************************************
Private Sub Command4_Click()
Dim PreopPrint As Integer
Dim mDb As Database
Dim qry As QueryDef
Dim xQryCtr As Integer, xRs As Recordset
Set mDb = CurrentDb

PreopPrint = MsgBox("Are you sure?", vbExclamation + vbOKCancel, "'OK' will Print The CC PRE Queries")
If PreopPrint = 1 Then
With mDb
For xQryCtr = 0 To .QueryDefs.Count - 1
If UCase$(Left(.QueryDefs(xQryCtr).Name, 5)) = "qryCC" Then
Set xRs = .QueryDefs(xQryCtr).OpenRecordset
If xRs.RecordCount > 0 Then
DoCmd.OpenQuery .QueryDefs(xQryCtr).Name, acViewNormal
DoCmd.PrintOut
DoCmd.Close acQuery, .QueryDefs(xQryCtr).Name
End If
Set xRs = Nothing
End If
Next
End With

Else: End If
Set mDb = Nothing
End Sub

Can someone suggest something where if the query has been changed and the field now no longer exists in the table, a message will tell what query generated it when the routine halts instead of just halting, going into the code, and giving me an error message regarding this line?:
For xQryCtr = 0 To .QueryDefs.Count - 1
Now I have to open every query in that section to see which generates a parameter request that is not part of the query, then check the query design. Thanks!
 
What you need to do is capture the whole query name in a variable, than use the good old ON ERROR command and print the msgbox the variable to display the query that was running at the time of the error.
 
Error trapping

How would I do that? All the preop queries start with qryCC PRE and then the actual query name, so do I make a variable for each set (qryCC PRE, qry CD POST, etc) or one that covers all the queries no matter what the set? Can you give me an example? Thank you!
 

Users who are viewing this thread

Back
Top Bottom