disable MsgBox

M

Mark

Hi,

I have a form ("ClassCalendar") with a calendar on it to
allow the user to select a date range and to view
available classes within that date range... upon selecting
a date range (Clicking a command button)... a "class
registration" form is then opened with a list of available
classes to enroll in. On the "ClassRegistration" form I
have the following code (which works fine... please read
my question at the bottom of this page):


Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Form_Open

If IsNull(DLookup("ClassID", "QueryClassesByDate"))_
Then
MsgBox "There are no classes offered within the selected_
date range. Please select another date range or exit_
form.", vbInformation, "Re-enter date range"
DoCmd.Close
Cancel = True
End If

Exit_Form_Open:
Exit Sub

Err_Form_Open:
MsgBox Err.Description
Resume Exit_Form_Open
End Sub


The situation is:
when the user is in the calendar form and selects a date
range with no classes sheduled... the message box pops up
(as in the above code). Fine. But after clicking "Ok"...
another message box appears... it is a standard Microsoft
Access MsgBox that states the following:

"The OpenForm action was canceled."

How can I disable or turn off this message box (to clean
up my database)???

Thanks a million!!!
 
V

Van T. Dinh

The error is generated by the CommandButton_Click Event because the Form
opening was started by it but then cancelled by the Form_Open Event.

You need to trap and ignore the error (ErrorNo 2501, I think) in the
CommandButton_Click Event.

Check Access VB Help on error-trapping.
 
B

bzamfir

Hi,

In the calling for, in the Click event, you have to add a error handler,
which actually will do nothing

The second message box is because when a form opening is canceled, Access
trigger an exception

So your calling code should looks like this:

sub Command1_click

on error goto Command1_click_err

docmd.openform "yourform", ....

Command1_click_exit:
exit sub

Command1_click_err:
resume Command1_click_exit
end sub


HTH,
Bogdan

_______________________________
Independent consultant
 
M

Mark

Hi Bogdan and Van,

Thanks for the insight and help!!!!!!!!!! Have a great
weekend!!!!!
 

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