Running a query and if successful run another

  • Thread starter Thread starter Annelie
  • Start date Start date
A

Annelie

Something is wrong with my code. If there is a problem with the data, I want
to exit the code. If there is no error, I want to proceed and call the
CmdDelete_Click, but it just goes on and deletes the data anyway. I am not
sure where to put the call statement

Private Sub CmdAppend_Click()
On Error GoTo Err_CmdAppend_Click

DoCmd.OpenQuery "3c-QryAppendNewEmpl1"
Me.Requery
Exit_CmdAppend_Click:
Exit Sub

Err_CmdAppend_Click:
MsgBox "There is a problem with duplicate Social Security Number or
Duplicate Name"

Resume Exit_CmdAppend_Click

End Sub
 
Maybe you could provide some more info about what it is
you are trying to do. The code example you posted doesn't
do anything except open a stored query (which - judging by
the name - appears to be an append query, not a delete query),
and then requeries the form's record source.

At no point in that code do you call any cmdDelete_Click
procedure or provide any instructions as to what your
procedure should do if some condition is/is not met.

Did you post the wrong code?
 
I am taking employees from the temporary table and I am apending them to the
TblEmployees. If the apend executes without an error the employee(s) are
deleted from the Temp table.
I am trying to understand how the procedures works.
Following this through, it would seems, that Call CmdDelete_Click could only
be right before Me.requery, because if there is no error, both queries
execute. I think I answered my own question.
 
Back
Top