Need Code to check to see If Form is Open and if so Then Close it

D

Dave Elliott

Form name is TimeCards
I have a macro that closes the database named Shutdown
its action is Quit and the options is SaveAll
I need to be able to check to see if the form TimeCards is open, and if it
is close it and then close DB.
 
K

Ken Snell

When you close the database, it will automatically close all open forms.
What do you want to do differently that you need/want to close the TimeCards
form via code first?

You can just use code step
DoCmd.Close acForm, "TimeCards"

and if the form is open, it'll be closed. If it's not open, the code goes on
without an error.
 
D

Dave Elliott

I need to close the form TimeCards because if it is open it will produce a
debug error.
I want to close the form TimeCards and then close the database with code.


--
Thanks for your help.
Ken Snell said:
When you close the database, it will automatically close all open forms.
What do you want to do differently that you need/want to close the TimeCards
form via code first?

You can just use code step
DoCmd.Close acForm, "TimeCards"

and if the form is open, it'll be closed. If it's not open, the code goes on
without an error.
 
K

Ken Snell

Just use these two steps then:

DoCmd.Close acForm, "TimeCards"
DoCmd.Quit


--
Ken Snell
<MS ACCESS MVP>

Dave Elliott said:
I need to close the form TimeCards because if it is open it will produce a
debug error.
I want to close the form TimeCards and then close the database with code.


--
Thanks for your help.
Ken Snell said:
When you close the database, it will automatically close all open forms.
What do you want to do differently that you need/want to close the TimeCards
form via code first?

You can just use code step
DoCmd.Close acForm, "TimeCards"

and if the form is open, it'll be closed. If it's not open, the code
goes
on
without an error.
if
 
A

Alex Elbert

Actually, the best way to do that is to use
Dim frm as For
For each frm in Form
' check names here or jus
Docmd.close acForm,frm.Nam
Nex
 

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