PC Review


Reply
Thread Tools Rate Thread

Closing Forms.

 
 
CEL504
Guest
Posts: n/a
 
      3rd Feb 2010
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>
 
Reply With Quote
 
 
 
 
Daniel Pineault
Guest
Posts: n/a
 
      3rd Feb 2010
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>

 
Reply With Quote
 
 
 
 
Mark A. Sam
Guest
Posts: n/a
 
      4th Feb 2010
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" <(E-Mail Removed)> wrote in message
news:8EF20FD3-E640-43DC-84D3-(E-Mail Removed)...
> 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>



 
Reply With Quote
 
Mark A. Sam
Guest
Posts: n/a
 
      4th Feb 2010
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
>



 
Reply With Quote
 
Mark A. Sam
Guest
Posts: n/a
 
      4th Feb 2010
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" <(E-Mail Removed)> wrote in message
news:8EF20FD3-E640-43DC-84D3-(E-Mail Removed)...
> 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>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Closing event in a MID Child form I don't know if the child form is closing or the main form is closing **Developer** Microsoft C# .NET 1 19th Oct 2005 04:51 PM
Word closing when closing document =?Utf-8?B?TG9yaQ==?= Microsoft Word Document Management 0 7th Mar 2005 04:41 PM
Stopping a form from closing in its Closing hander Tom Jones Microsoft Dot NET Framework Forms 2 26th Aug 2004 01:24 PM
Closing VB triggers closing Excel =?Utf-8?B?TWluaWxlaw==?= Microsoft Excel Programming 2 6th Aug 2004 05:17 PM
closing excel after closing a workbook CWalsh Microsoft Excel Programming 3 21st Jan 2004 04:33 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:14 PM.