Cancelling query launched from macro

  • Thread starter Thread starter Howard Brody
  • Start date Start date
H

Howard Brody

I'd try it with code.

In the OnClick property line, right click to get the
Build... option and select EventProcedure. When the VB
window opens, use this code:

Private Sub CommandButtonName_Click()
DoCmd.OpenQuery "qryQueryName", acViewNormal
End Sub

Hope this helps!

Howard Brody
 
Thanks so much for your help. That was close but if I
cancel the macro rather than entering data and clicking
OK, it returns the following error message:

Run time error '2001':
You cancelled the previous operation

I went back and looked at the code to verify it is a
duplicate of what you stated here. Any thoughts?

Thanks again,
Tom
 
Try this this code instead:

Private Sub Command1_Click()
On Error GoTo Err_Command0_Click
DoCmd.OpenQuery "qry_MyQuery", acViewNormal

Err_Command0_Click:
Exit Sub


End Sub

 
Back
Top