ErrorHandler:
‘Excel is not running; open Excel with CreateObject
If Err.Number = 429 Then
Set appExcel = CreateObject(“Excel.Application”)
Resume Next
Else
MsgBox “Error No: “ & Err.Number & “; Description: “
Resume ErrorHandlerExit
End IfEnd SubPublic Function CreateAndTestQuery(strTestQuery As String, _
strTestSQL As String) As LongThis function is called from other procedures to create a filtered query, using a SQL string in its
strTestSQLargument:On Error Resume NextDim qdf As DAO.QueryDef‘Delete old query
Set dbs = CurrentDb
dbs.QueryDefs.Delete strTestQueryOn Error GoTo ErrorHandler‘Create new query
Set qdf = dbs.CreateQueryDef(strTestQuery, strTestSQL)‘Test whether there are any records
Set rst = dbs.OpenRecordset(strTestQuery)
With rst
.MoveFirst
.MoveLast
CreateAndTestQuery = .RecordCount
End WithErrorHandlerExit:
Exit FunctionErrorHandler:
If Err.Number = 3021 Then
CreateAndTestQuery = 0
Resume ErrorHandlerExit
Else
MsgBox “Error No: “ & Err.Number & “; Description: “ &
Err.Description
Resume ErrorHandlerExit
End IfPart I The Office Components and What They Do Best