parameter box cancel button

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a query built by the query builder that has parameters. When I run the
query a window opens asking for the criteria. If I hit the cancel button in
this window, I get an runtime error '2501'. How can i fix this?

Thanks.
 
I have a query built by the query builder that has parameters. When I run the
query a window opens asking for the criteria. If I hit the cancel button in
this window, I get an runtime error '2501'. How can i fix this?

Thanks.

Trap the error in the command button code event that you used to open
the query:

On Error GoTo Err_Handler
DoCmd.OpenQuery "QueryName"

Exit_This_Event:
Exit Sub
Err_Handler:
If Err = 2501 then
Else
MsgBox "Error #: " & Err.Number & " " & Err.Description
End If
Resume Exit_This_Event
 
That worked, thanks!

fredg said:
Trap the error in the command button code event that you used to open
the query:

On Error GoTo Err_Handler
DoCmd.OpenQuery "QueryName"

Exit_This_Event:
Exit Sub
Err_Handler:
If Err = 2501 then
Else
MsgBox "Error #: " & Err.Number & " " & Err.Description
End If
Resume Exit_This_Event
 
Back
Top