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

  • Thread starter Thread starter Dave Elliott
  • Start date Start date
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.
 
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.
 
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.
 
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
 
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
 
Back
Top