How to close form if code is still processing?

H

HeislerKurt

I have a form which pops up when the user clicks on a button.

The form is used to enter patient information (name, etc.). When the
user exits the last name field, code checks to see if a person with
the same first & last name is already in the table. If it finds a
possible duplicate, a message pops up and gives the user the option of
continuing (Yes or No).

If he clicks No, the message goes away and he's back to the form. How
can I have this form close automatically when he clicks No? If I
put ...

DoCmd.Close acForm, "frmNewPatient"

.... in with the LastName Exit code, I get:

"Run-time error 2585: This action can't be carried out while
processing a form or report event."

.... because the form's code is still processing. How can get around this
and get the form to close?

Thank you.

Relevant code below:

###

Pt_LName_Exit
....
If MsgBox(sMsg, vbYesNo + vbDefaultButton2, "Possible Duplicate ")
<> vbYes Then
Cancel = True
Me.Undo

' this is the logical time to close the form, but it causes the
2585 error
' DoCmd.Close acForm, "frmNewPatient"

End If
....
End Sub
 
H

HeislerKurt

I spoke too soon.

I moved this code to the BeforeUpdate event of the Last Name control,
which allows me to use the DoCmd close line in the code.
 
B

bliddel

I spoke too soon.

I moved this code to the BeforeUpdate event of the Last Name control,
which allows me to use the DoCmd close line in the code.
Well, maybe you didn't after all.

I have a main form which triggers another form with a command button. My
targeted user may or may not remember to close the smaller form with the
button I provided. If this person clicks back on the main form, it will then
cover the smaller form (which is totally unbound), only to reappear later on
when the user finally decides to close the main form. By this time the user
will have forgotten why the smaller form was ever loaded, and will call to
ask me what is wrong with my program.

I would like to simply close the smaller form if the user clicks away from
it, but I also run into this same error 2585 obstacle. I could make the
smaller form modal, but I think that is just plain rude. (I'm a big fan of
Alan Cooper, wouldn't you know?)

It seems rather absurd that there should be special conditions preventing
closure of an unbound form that has lost the focus, but here we are.

Ideas anyone?
 
J

J_Goddard via AccessMonster.com

I don't think making the smaller form modal is rude at all; it forces the
users to do things in the proper order. If your user "may or not remember...
" then IMHO they need a little "guidance". Besides, if you closed the form
when the user clicked away from it, that level of user would be sure to
complain that the form closed before they had finished with it!!

All us developers know the biggest problem many users have is the chair-to-
keyboard interface. So, make your form modal - it will minimize complaints.

Cheers!

John
 
D

Dirk Goldgar

bliddel said:
Well, maybe you didn't after all.

I have a main form which triggers another form with a command button. My
targeted user may or may not remember to close the smaller form with the
button I provided. If this person clicks back on the main form, it will
then
cover the smaller form (which is totally unbound), only to reappear later
on
when the user finally decides to close the main form. By this time the
user
will have forgotten why the smaller form was ever loaded, and will call to
ask me what is wrong with my program.

I would like to simply close the smaller form if the user clicks away from
it, but I also run into this same error 2585 obstacle. I could make the
smaller form modal, but I think that is just plain rude. (I'm a big fan
of
Alan Cooper, wouldn't you know?)

It seems rather absurd that there should be special conditions preventing
closure of an unbound form that has lost the focus, but here we are.

Ideas anyone?


How about using the Close event of the main form to close the small form?

Private Sub Form_Close()

DoCmd.Close acForm, "SmallerForm", acSaveNo

End Sub

Since you say the smaller form is unbound, you shouldn't have to worry about
having to save any record from that form.
 

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