View Full Version : Message Box Help


build
10-20-2000, 06:12 AM
Hi

Access 97

I have a query and in one of the fields under criteria I have [Forms]![frmWhatToDoOnTheDay]![lngBookingID].

when I run the query a message box comes up (ENTER PARAMETER VALUE) asking for what date.

Now all is ok if I put in the date, BUT if I press the Cancel button I then get a Run time error 2501.The open form action was cancelled
you must use a method of the DoCmd etc etc. If then I press end It closes the data base down.

Now if I start my data base with Shift then open it up then open the form then run the query press cancel it would take me
back to the table forms report etc.

So how can I get it to go back to my start up form when I press cancel when the data base is locked.

Or if cancel was pressed could I have my own message box and program that?

If so how do you do this..


Regards

John

stonesby@ntlworld.com
john@stonesby.demon.co.uk
rymarks@btinternet.com

R. Hicks
10-22-2000, 05:25 PM
Error 2501 is generated by the user clicking Cancel. You'll need to add error handling to fix your problem.
You don't say how you are triggering query to run, but let's say you are using a cmdbutton. We'll name it cmdYourButton. Here is the simplest way to avoid the problem (not the best):

Add "On Error Resume Next" as the second line of code:

'***********Begin Code**************
Private Sub cmdYourButton_Click()
On Error Resume Next

'Add your code here...........

End Sub
'***********End Code**************

Here is the better way:
If you want to capture the error to give your own message use something like:

'***********Begin Code**************
Private Sub cmdYourButton_Click()
On Error GoTo Err_cmdYourButton

'Add your code here...........

Exit_cmdYourButton:
Exit Sub

Err_cmdYourButton
If Err.Number = 2501 Then
'Add your Custom Message here.......
Else
MsgBox Err.Description
Resume Exit_cmdYourButton
End Sub
'***********End Code**************

HTH
RDH

[This message has been edited by R. Hicks (edited 10-22-2000).]