Error handler

arage

Registered User.
Local time
Today, 17:22
Joined
Dec 30, 2000
Messages
537
Error handler

Set qd = db.CreateQueryDef("qryDtlMgrMth" & i, "SELECT tblPromotionType.promotionType, Manager.Code, Manager.DirectorCode, tblYear.Year, tblMonth.Month, tblMonth.MonthName, Manager.ManagerName FROM Manager, tblMonth, tblPromotionType, tblYear GROUP BY tblPromotionType.promotionType, Manager.Code, Manager.DirectorCode, tblYear.Year, tblMonth.Month, tblMonth.MonthName, Manager.ManagerName ORDER BY tblPromotionType.promotionType, Manager.Code, Manager.DirectorCode, tblMonth.Month;")

errorHandler:
Select Case err.number
'qry exists already...
Case 3012
Exit Sub
End Select

The above SET statement creates error 3012 when i try to create my query definition. As such I created the ERROR HANDLER statement just above as well. Problem is when the error occurs, nothing happens, the ERROR HANDLER does not receive control of the flow at this point, why is this? Please note that the SET statement does appear within a SELECT CASE statement nested within a FOR loop which itself occurs within another SELECT CASE statement.
 
Does This Line appear in your code above the Select statement:

On Error Goto errorHandler


This is the tag that tells the VBA where to go if an error occurs. If not present you get MS Access's ErrorHandler (Message box, and in run time versions kickout):)
 
Thanks, my On Error GoTo errorHandler wasn’t at the start of my procedure but right before the errorHandler label! Now it works!
 

Users who are viewing this thread

Back
Top Bottom