A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Closing Forms.



 
 
Thread Tools Display Modes
  #1  
Old February 3rd, 2010, 02:10 PM posted to microsoft.public.access.forms
cel504
external usenet poster
 
Posts: 39
Default Closing Forms.

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
  #2  
Old February 3rd, 2010, 04:45 PM posted to microsoft.public.access.forms
Daniel Pineault
external usenet poster
 
Posts: 658
Default Closing Forms.

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.



"CEL504" wrote:

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

  #3  
Old February 4th, 2010, 01:32 PM posted to microsoft.public.access.forms
Mark A. Sam[_3_]
external usenet poster
 
Posts: 468
Default Closing Forms.

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


"CEL504" wrote in message
...
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



  #4  
Old February 4th, 2010, 01:55 PM posted to microsoft.public.access.forms
BruceM via AccessMonster.com
external usenet poster
 
Posts: 448
Default Closing Forms.

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.

Mark A. Sam wrote:
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


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/201002/1

  #5  
Old February 4th, 2010, 02:15 PM posted to microsoft.public.access.forms
Mark A. Sam[_3_]
external usenet poster
 
Posts: 468
Default Closing Forms.

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" u54429@uwe wrote in message
news:a321bedacfd39@uwe...
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.

Mark A. Sam wrote:
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


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/201002/1



  #6  
Old February 4th, 2010, 02:19 PM posted to microsoft.public.access.forms
Mark A. Sam[_3_]
external usenet poster
 
Posts: 468
Default Closing Forms.

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




"CEL504" wrote in message
...
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



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 01:20 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.