Skip query if invalid or syntax error

E

Eric

Some times query returns null, invalid value or syntax error based on
Forms!tbl_PPVResearch_Edit!frm_Events!TicketNum. User input wrong
ticket number, is it possible that before i execute the query i will
check if its valid then execute other wise skip

Private Sub updt()
Dim qry As String, rst As Object
qry = "UPDATE tbl_Events INNER JOIN tbl_EquipmentChronology ON
tbl_Events.TicketNum = tbl_EquipmentChronology.TicketNum SET
tbl_Events.txt =
IIf(nz([tbl_EquipmentChronology].[Equipment3],'')<>'',[tbl_EquipmentChronology].[Equipment3],IIf(nz([tbl_EquipmentChronology].[Equipment2],'')<>'',[tbl_EquipmentChronology].[Equipment2],[tbl_EquipmentChronology].[Equipment1]))
WHERE (((tbl_Events.PPVVOD_Outlet)=[Tbl_EquipmentChronology].[Outlet]
And (tbl_Events.PPVVOD_Outlet)<>0) AND (tbl_events.TicketNum)=" &
Forms!tbl_PPVResearch_Edit!frm_Events!TicketNum & ")"
CurrentDb.Execute qry
End Sub

Thanks,
 
M

Michael H

Hi.

Just perform your test of that field's value as the first thing in the
procedure. If the test fails, then Exit Sub.

Also, if possible, you may want to consider running your query with the
dbFailOnError option, which will roll back updates if there is an error:
CurrentDb.Execute qry, dbFailOnError

-Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top