Closing Forms.

  • Thread starter Thread starter CEL504
  • Start date Start date
C

CEL504

Help please! How do I get a form to close on exit. I have used a switchbord
form where I navigate to other forms in the data base, what is the best way
to close a form automatically I have finished reviewing it and I return back
to the switchboard again?

I have read some of the threads but still unsure where the code is written to.


Cel504, many thanks>
 
One option is to open your forms in modal modal so user have to close the
form themselves before being able to go elsewhere.

Another option would be to use the form's got focus event to close all open
forms. Something like:

Dim DbF As Form
Dim DbO As Object

Set DbO = Application.Forms 'Collection of all the open forms

For Each DbF In DbO 'Loop all the forms
If DbF.Name <> "SwitchboardFormName" Then
DoCmd.Close acForm, DbF.Name
End If
Next DbF

Set DbO = Nothing
--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.
 
CEL,

In either the Form's Deactivate or LostFocus event paste this code,
adjusting for the Form name:


Private Sub Form_LostFocus()

Exit Sub
DoCmd.Close acForm, "Form4"

End Sub

CEL,

The best way is to put a Close button on the form with code like this in the
CLick event:

Private Sub btnClose_Click()

DoCmd.Close acForm, "Form4"
DoCmd.OpenForm "Switchboard" 'If Switchboard is the name of the form to go
to

End Sub

This will bring up the switchboard whether or not it is open.

God Bless,

Mark A. Sam
 
It doesn't. I was just playing around and thought I had that working. I
didn't mean to post that portion. If you scroll down you will see that I
suggested a close button. Sorry for the confusion.



BruceM via AccessMonster.com said:
I don't see how it will work to have Exit Sub before the code to close the
form.

I think the command button code is the way to go, since the user
presumably
has to click a button (or something) to return to the switchboard. Also,
it
should be possible to use Me.Name instead of the form name:

DoCmd.Close acForm, Me.Name

It doesn't work any differently than if the form is named, but I find it
more
convenient.

It may not be necessary to open the switchboard form, as it may not have
been
closed when Form4 was opened.
CEL,

In either the Form's Deactivate or LostFocus event paste this code,
adjusting for the Form name:

Private Sub Form_LostFocus()

Exit Sub
DoCmd.Close acForm, "Form4"

End Sub

CEL,

The best way is to put a Close button on the form with code like this in
the
CLick event:

Private Sub btnClose_Click()

DoCmd.Close acForm, "Form4"
DoCmd.OpenForm "Switchboard" 'If Switchboard is the name of the form to
go
to

End Sub

This will bring up the switchboard whether or not it is open.

God Bless,

Mark A. Sam
Help please! How do I get a form to close on exit. I have used a
switchbord
[quoted text clipped - 8 lines]
Cel504, many thanks>
 
Disregard my first post. I was playing around and thought I had the
procedure working, but wasn't thinking properly. I left that part in by
mistake. So here is my correction.

The best way is to put a Close button on the form with code like this in the
CLick event:

Private Sub btnClose_Click()

DoCmd.Close acForm, "Form4"
DoCmd.OpenForm "Switchboard" 'If Switchboard is the name of the form to go
to

End Sub

This will bring up the switchboard whether or not it is open.

God Bless,

Mark A. Sam
 
Back
Top