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,
 
G

Guest

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

Similar Threads

Syntax Error in FROM clause 2
Link a query to show more fields 5
Need help with Date Query 2
Error: Too few paramenters 7
Query as recordset 4
Crosstab & Query by Form 1
SQL Error 3
syntax error in update query 1

Top