I've got a form button that fires off 3 queries but if the first query
returns an error, I don't want the other two queries to happen.
Example: first query runs an insert from a linked table but if for some
reason a field is missing a value that's required, Access throws up an
error. At that point I just want to end the process and notify them of the
error so they can correct the data and try the process again.
Here's my code:
DoCmd.OpenQuery "download_recor ds_clear", acNormal, acEdit (clears
a temp table)
DoCmd.OpenQuery "download_recor ds", acNormal, acEdit (downloads
linked records)
DoCmd.OpenQuery "download_recor ds_set", acNormal, acEdit (update
linked records d/l value)
Well if Query "download_recor ds" doesn't go well, I don't want to do query
"download_recor ds_set".
Is there some sort of error checking I can put in between those two lines?
Here's the complete code for that button:
------------------------------------------------------
Private Sub ImportWebFiles_ Click()
Dim qryOption As Boolean
On Error GoTo Err_ImportWebFi les_Click
qryOption = Application.Get Option("Confirm Action Queries")
Application.Set Option "Confirm Action Queries", False
DoCmd.OpenQuery "download_recor ds_clear", acNormal, acEdit
DoCmd.OpenQuery "download_recor ds", acNormal, acEdit
DoCmd.OpenQuery "download_recor ds_set", acNormal, acEdit
MsgBox "Records downloaded."
Application.Set Option "Confirm Action Queries", qryOption
Exit_ImportWebF iles_Click:
Exit Sub
Err_ImportWebFi les_Click:
MsgBox Err.Description
Application.Set Option "Confirm Action Queries", qryOption
DoCmd.SetWarnin gs True
Resume Exit_ImportWebF iles_Click
End Sub
------------------------------------------------------------
returns an error, I don't want the other two queries to happen.
Example: first query runs an insert from a linked table but if for some
reason a field is missing a value that's required, Access throws up an
error. At that point I just want to end the process and notify them of the
error so they can correct the data and try the process again.
Here's my code:
DoCmd.OpenQuery "download_recor ds_clear", acNormal, acEdit (clears
a temp table)
DoCmd.OpenQuery "download_recor ds", acNormal, acEdit (downloads
linked records)
DoCmd.OpenQuery "download_recor ds_set", acNormal, acEdit (update
linked records d/l value)
Well if Query "download_recor ds" doesn't go well, I don't want to do query
"download_recor ds_set".
Is there some sort of error checking I can put in between those two lines?
Here's the complete code for that button:
------------------------------------------------------
Private Sub ImportWebFiles_ Click()
Dim qryOption As Boolean
On Error GoTo Err_ImportWebFi les_Click
qryOption = Application.Get Option("Confirm Action Queries")
Application.Set Option "Confirm Action Queries", False
DoCmd.OpenQuery "download_recor ds_clear", acNormal, acEdit
DoCmd.OpenQuery "download_recor ds", acNormal, acEdit
DoCmd.OpenQuery "download_recor ds_set", acNormal, acEdit
MsgBox "Records downloaded."
Application.Set Option "Confirm Action Queries", qryOption
Exit_ImportWebF iles_Click:
Exit Sub
Err_ImportWebFi les_Click:
MsgBox Err.Description
Application.Set Option "Confirm Action Queries", qryOption
DoCmd.SetWarnin gs True
Resume Exit_ImportWebF iles_Click
End Sub
------------------------------------------------------------
Comment