|
Prev: syntax error missing operator
Next: Edit a pdf document
From: jlute on 30 Jun 2008 09:48 I have a criteria form from which I preview/print reports and need to close all open forms EXCEPT the criteria form and a main menu prior to previewing/printing. What I'd like to do is click the preview or print button which will close the forms prior to executing other commands. Is there a simple code to do this? I've searched through the groups and have found some very complex codes. Thanks!!!
From: Dennis on 30 Jun 2008 10:33 Dim i As Integer Dim strForm as String For i = 1 To CurrentProject.AllForms.Count If CurrentProject.AllForms(i - 1).IsLoaded Then strForm = CurrentProject.AllForms(i - 1).Name If strForm <> "criteria form" And strForm <> "main menu" Then DoCmd.Close acForm, strForm, acSaveNo End If End If Next i "jlute(a)marzetti.com" wrote: > I have a criteria form from which I preview/print reports and need to > close all open forms EXCEPT the criteria form and a main menu prior to > previewing/printing. > > What I'd like to do is click the preview or print button which will > close the forms prior to executing other commands. Is there a simple > code to do this? I've searched through the groups and have found some > very complex codes. > > Thanks!!! >
From: Dirk Goldgar on 30 Jun 2008 10:50 <jlute(a)marzetti.com> wrote in message news:55b99c18-0d12-44c5-b9b5-2822c3472a23(a)l42g2000hsc.googlegroups.com... >I have a criteria form from which I preview/print reports and need to > close all open forms EXCEPT the criteria form and a main menu prior to > previewing/printing. > > What I'd like to do is click the preview or print button which will > close the forms prior to executing other commands. Is there a simple > code to do this? I've searched through the groups and have found some > very complex codes. John - Here's a routine you can call to close all forms except a list you specify as arguments when you call it: '----- start of code ----- Sub CloseAllFormsExcept(ParamArray ExceptForm()) ' Copyright (c) 2008, DataGnostics LLC ' License is granted to use in your application, so long as ' the copyright notice remains unchanged. Dim lngFrm As Long Dim intX As Integer Dim blnPreserve As Boolean ' Close all open forms except those in the list. For lngFrm = Forms.Count - 1 To 0 Step -1 With Forms(lngFrm) blnPreserve = False For intX = LBound(ExceptForm) To UBound(ExceptForm) If .Name = ExceptForm(intX) Then blnPreserve = True Exit For End If Next intX If blnPreserve Then ' Spare this form Else DoCmd.Close acForm, .Name End If End With Next lngFrm End Sub '----- end of code ----- -- Dirk Goldgar, MS Access MVP www.datagnostics.com (please reply to the newsgroup)
From: jlute on 30 Jun 2008 11:34 Thanks, Dennis! That's a simple and nifty one! On Jun 30, 10:33 am, Dennis <Den...(a)discussions.microsoft.com> wrote: > Dim i As Integer > Dim strForm as String > > For i = 1 To CurrentProject.AllForms.Count > If CurrentProject.AllForms(i - 1).IsLoaded Then > strForm = CurrentProject.AllForms(i - 1).Name > If strForm <> "criteria form" And strForm <> "main menu" Then > DoCmd.Close acForm, strForm, acSaveNo > End If > End If > Next i > > > > "jl...(a)marzetti.com" wrote: > > I have a criteria form from which I preview/print reports and need to > > close all open forms EXCEPT the criteria form and a main menu prior to > > previewing/printing. > > > What I'd like to do is click the preview or print button which will > > close the forms prior to executing other commands. Is there a simple > > code to do this? I've searched through the groups and have found some > > very complex codes. > > > Thanks!!!- Hide quoted text - > > - Show quoted text -
From: jlute on 30 Jun 2008 11:37 Hi, Dirk! Long time no see! Thanks - this is a powerful solution, too! Not sure which I'm going to use but I certainly appreciate the fact that there's always such diversity in responses here! On Jun 30, 10:50 am, "Dirk Goldgar" <d...(a)NOdataSPAMgnostics.com.invalid> wrote: > <jl...(a)marzetti.com> wrote in message > > news:55b99c18-0d12-44c5-b9b5-2822c3472a23(a)l42g2000hsc.googlegroups.com... > > >I have a criteria form from which I preview/print reports and need to > > close all open forms EXCEPT the criteria form and a main menu prior to > > previewing/printing. > > > What I'd like to do is click the preview or print button which will > > close the forms prior to executing other commands. Is there a simple > > code to do this? I've searched through the groups and have found some > > very complex codes. > > John - > > Here's a routine you can call to close all forms except a list you specify > as arguments when you call it: > > '----- start of code ----- > Sub CloseAllFormsExcept(ParamArray ExceptForm()) > > ' Copyright (c) 2008, DataGnostics LLC > ' License is granted to use in your application, so long as > ' the copyright notice remains unchanged. > > Dim lngFrm As Long > Dim intX As Integer > Dim blnPreserve As Boolean > > ' Close all open forms except those in the list. > > For lngFrm = Forms.Count - 1 To 0 Step -1 > With Forms(lngFrm) > blnPreserve = False > For intX = LBound(ExceptForm) To UBound(ExceptForm) > If .Name = ExceptForm(intX) Then > blnPreserve = True > Exit For > End If > Next intX > If blnPreserve Then > ' Spare this form > Else > DoCmd.Close acForm, .Name > End If > End With > Next lngFrm > > End Sub > > '----- end of code ----- > > -- > Dirk Goldgar, MS Access MVPwww.datagnostics.com > > (please reply to the newsgroup)
|
Pages: 1 Prev: syntax error missing operator Next: Edit a pdf document |