parameter box cancel button

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.
 
F

fredg

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
 
G

Guest

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
 

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

Top