UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
2 Pages V < 1 2  (Go to first unread post)
   Reply to this topicStart new topic
> vba to close all open forms    
 
   
BuzyG
post Jun 18 2019, 11:06 AM
Post#21



Posts: 417
Joined: 20-September 12
From: Cornwall UK


One I adapted from the internet many moons ago. Similar to what others have posted. One extra trick here is that you can exclude any forms you wish to leave open. I use this routine a lot, to close down forms, but always leave open the main form and hidden user permissions form. Hope it helps.

CODE
Public Function CloseForms(ParamArray Exclusions()) As Byte
  'This procedure will close all the forms open except for the ones passed through
  'The argument list.  Only declared as a function for flexibility.  No meaningful
  'data is returned. Note that "Join" is used, which is not available in A97.
  '**** Example **** CloseForms ("frmRepairData!frmMainMenu!frmAdministration!frmUserReports")
  Dim strExcluded As String
  Dim intX As Integer, intY As Integer
  Const cDelimiter As String = "!" 'chose ! simply because it is not allowed in a form name
  'Concatenate all the excluded form names
  strExcluded = cDelimiter & Join(Exclusions, cDelimiter) & cDelimiter
  'Loop all the forms and close them as appropriate
  For intX = Forms.Count - 1 To 0 Step -1
    If InStr(1, strExcluded, cDelimiter & Forms(intX).NAME & cDelimiter, vbTextCompare) = 0 Then
      DoCmd.Close acForm, Forms(intX).NAME, acSaveNo
    End If
  Next intX
  Do While Reports.Count > 0
    DoCmd.Close acReport, Reports(0).NAME
  Loop
End Function

--------------------
Live to Surf
Go to the top of the page
 
theDBguy
post Jun 18 2019, 11:22 AM
Post#22


Access Wiki and Forums Moderator
Posts: 75,724
Joined: 19-June 07
From: SunnySandyEggo


Hi BuzyG. Looks like you may have gotten it from Post #5 of this very same thread. It was posted back in '09.

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
BuzyG
post Jun 18 2019, 11:28 AM
Post#23



Posts: 417
Joined: 20-September 12
From: Cornwall UK


theDBGuy

LoL Yes mist that. Does look like exactly the same source. Thx who ever wrote it originally. thumbup.gif
This post has been edited by BuzyG: Jun 18 2019, 11:28 AM

--------------------
Live to Surf
Go to the top of the page
 
isladogs
post Jun 18 2019, 11:29 AM
Post#24


UtterAccess VIP
Posts: 1,455
Joined: 4-June 18
From: Somerset, UK


Hi PhilC
My apologies. This thread now has so many bits of code, I'm losing the plot

--------------------
Go to the top of the page
 
2 Pages V < 1 2


Custom Search


RSSSearch   Top   Lo-Fi    20th July 2019 - 02:30 AM