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!
'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!