View Full Version : Code to close a form IF it is open


Terpsichore
03-10-2008, 11:31 AM
Hi,

I'm trying to create a button that when clicked, if certain forms are open, they get closed before running the rest of the code. But, I have no idea how to specify this or if it is possible. i.e. if Forms![employees] is Open then ... (i know the code for close a form).

Thoughts?

tia
Angel

Brianwarnock
03-10-2008, 11:51 AM
Don't double post.

wazz
03-10-2008, 12:03 PM
look for 'IsLoaded' in help (or this forum).

Terpsichore
03-10-2008, 12:03 PM
Sorry. At first I didn't realize this would be the more appropriate place to post. I've deleted the other post.

Wazz, I have searched under the IsLoaded property but I can't seem to build the code so that it works.

Please advise.

tia
angel

Brianwarnock
03-10-2008, 03:21 PM
If CurrentProject.AllForms("formname").IsLoaded Then
DoCmd.Close acForm, "formname", acSaveYes
End If

Brian

Terpsichore
03-11-2008, 08:04 AM
Thank you, Brianwarnock. Worked like a charm. I was missing the currentproject bit.

Thanks.