Form Lost Focus

  • Thread starter Thread starter Mary Fetsch
  • Start date Start date
M

Mary Fetsch

In Access 2000, I have a Patient form and a Doctor form. The Patient form
can be opened from the Doctor form, as well as from other forms. I would
like to require the user to close the Patient form before moving out of it,
or at least display a message when if the user doesn't close the form. I
can't check for this in another form because I don't know just which form
the user will move to.

The Patient form may not be updated, so I can't use a Before_Update event.
The form's Lost Focus event doesn't fire because I have controls on the
form. I know I can open the Patient form as a modal form, but I'd rather
not do that.

So my question boils down to this: As the focus leaves a form, is there a
way to identify whether or not the form was closed?
 
Mary,

You will probably want to set the form's Modal property = Yes. This
property is locating on the "Other" tab in the form's property sheet. A
"Yes" setting will force the user to close the form before performing other
activities in the database.
 
Thanks for your response, Mike. I said in my post that I didn't want to
open it as a modal form. Is there any other way?
 
Sorry about that. I guess I was reading a little too fast.

You should be able to use the ActiveForm property as a tool to detect your
current form. The below air code should get you started. I have to run off
to a client meeting. Sorry for the terse response.

Dim frmCurrentForm As Form

Set frmCurrentForm = Screen.ActiveForm

If frmCurrentForm.Name <> "YourForm" Then
If SysCmd(acSysCmdGetObjectState, acForm, "YourForm") = Then
'Do something.
End If
End If

You may be able to put the above in one of your other form's events, perhaps
On Got Focus.
 
Thanks again for your response - I really appreciate your time. I already
have some code similar to what you suggested to check if a form's loaded. I
don't think I'll worry about closing the form when it loses focus, but
before it's called from another form, I'll check if it's loaded - if so,
I'll close it before opening it again. That way, variables, etc will be
initialized.
 
Back
Top