Cancel opening form

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

Hi all,

I have a form (formClassEdit) with a record source being a
query (queryClassEdit). From the switchboard (main page
of the database)... when the user clicks the command
button labeled "Edit Class"... the user is prompted to
enter the Class ID number... then the form is opened and
the fields/text boxes are filled based on the records
pulled from the query based on Class ID.

However, when there are no records returned by the query
the form opens up with a blank screen. I am trying to get
something like this to work: from the switchboard... upon
clicking the "Edit Class" command button and after
entering the Class ID when prompted... if no records are
returned by the query, instead of having the form open
up... can I get a message box to appear stating
that "there are no classes with that ID number"?... and
have the form not open up.

Thanks a bunch for the help!!!
 
check out the Form_Open event.
It has a Cancel argument, run your query, or even do the msgbox from the
form open event, if no records returned then set cancel to true. This
cancels the opening of the form.

you may want to write some error code if pesty access error windows show up.
check err.number in your error handler.
 
Back
Top