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  

Close all open forms



 
 
Thread Tools Display Modes
  #1  
Old August 19th, 2004, 11:41 AM
Mike
external usenet poster
 
Posts: n/a
Default Close all open forms

Whats the best way to close all open forms and open another one
can it be done within the same command button so that if someone opens
another form by clicking the relevant button the form that is already opened
should close 1st


Any Help would be great


  #2  
Old August 19th, 2004, 05:50 PM
Jim/Chris
external usenet poster
 
Posts: n/a
Default

This is one way

Public Function CloseAllForms(Optional ByVal ExceptName As
String = vbNullString)
Dim i As Integer
Dim x As Integer

x = Forms.Count - 1

For i = x To 0 Step -1
'The below will exclude a form if desired
If Forms(i).Name ExceptName Then

DoCmd.Close acForm, Forms(i).Name
End If
Next i
End Function

After this you could and an open form statement

Jim




-----Original Message-----
Whats the best way to close all open forms and open

another one
can it be done within the same command button so that if

someone opens
another form by clicking the relevant button the form that

is already opened
should close 1st


Any Help would be great


.

  #3  
Old August 19th, 2004, 05:58 PM
Allen Browne
external usenet poster
 
Posts: n/a
Default

Loop backwards through the Forms collection, issuing a Close on each one.

Dim lng As Long
For lng = Forms.Count - 1 To 0 Step -1
DoCmd.Close acForm, Forms(lng).Name, acSaveNo
Next

Please be aware that there is a nasty bug in Access: If an edit is in
progress, and cannot be saved (e.g. a required field has not yet been
entered), it just closes the form and you lose your entry. More info:
http://members.iinet.net.au/~allenbrowne/bug-01.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Mike" wrote in message
news:41248297.0@entanet...
Whats the best way to close all open forms and open another one
can it be done within the same command button so that if someone opens
another form by clicking the relevant button the form that is already
opened
should close 1st



 




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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Icon shows open envelope in send folder. Roger D. Thompson General Discussion 5 August 11th, 2004 06:07 PM
Document won't open Bob Stubbs General Discussion 4 August 3rd, 2004 05:45 AM
closing multiple forms MC Using Forms 4 July 26th, 2004 09:13 PM
docmd.close Terri General Discussion 4 July 20th, 2004 10:00 PM
Open Macro after Close Gerry Kuta Worksheet Functions 1 October 23rd, 2003 02:25 PM


All times are GMT +1. The time now is 03:50 AM.


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