Open a Form if a parameter Query is canceled.

The_Flying_Scot

New member
Local time
Today, 16:40
Joined
Nov 22, 2012
Messages
2
I am strugaling with this one!

Basicaly a user searches for data!

When they click the search button a parameter query is run! If the user presses cancel i want a specific form to open is this possiable.

Help is appreciated.

Regards
 
When will the user click Cancel? Is this when the parameter box pops up? Why would they click cancel?

There are no events associated with queries (On Open, On Close etc) so you can not run code off the back of the cancel button being clicked. The way to get around this however, is to provide a form for the user to enter or select their parameters. Perhaps the form would remove the need to click cancel. If you can answer the why, we may be able to assist further.
 
Hello Scot, Welcome to AWF.. :)

Try a error handler to handle that error..
Code:
Private Sub [COLOR=Blue]theBtn[/COLOR]_Click()
On Error GoTo cancelErr
    DoCmd.OpenQuery ("[COLOR=Blue]theQueryName[/COLOR]")
exitOnErr:
    Exit Sub
cancelErr:
    If Err.Number <> 2001 Then
        Call MsgBox("Error Occurred : " & Err.Description, vbInformation, Err.Number)
    Else
        DoCmd.OpenForm "[COLOR=Blue]theFormName[/COLOR]"
    End If
    Resume exitOnErr
End Sub
Change all blue bits..
 
Yes, didn't think about the error returning to the calling code. Good shout:D
 
When will the user click Cancel? Is this when the parameter box pops up? Why would they click cancel?.

I am trying to make the operation of a database cleaner.

I have a dashboard form which has numerous options, when a user clicks on an option the dashboard closes and he is left with a parameter Query box.

They would then enter the search criteria but if he clicked the option by mistake and wanted to cancel i would then require a specific form to pop up.

@pr2-eugin

i will give that a go it might do what i need i will run it and see

All

Thanks for what i can only say was a very very quick reply!


Regards
 
Hello Scot, Welcome to AWF.. :)

Try a error handler to handle that error..
Code:
Private Sub [COLOR=Blue]theBtn[/COLOR]_Click()
On Error GoTo cancelErr
    DoCmd.OpenQuery ("[COLOR=Blue]theQueryName[/COLOR]")
exitOnErr:
    Exit Sub
cancelErr:
    If Err.Number <> 2001 Then
        Call MsgBox("Error Occurred : " & Err.Description, vbInformation, Err.Number)
    Else
        DoCmd.OpenForm "[COLOR=Blue]theFormName[/COLOR]"
    End If
    Resume exitOnErr
End Sub
Change all blue bits..

I know this post is old but this piece of code has helped me no end. Thanks muchly
 

Users who are viewing this thread

Back
Top Bottom