Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / June 2008

Tip: Looking for answers? Try searching our database.

close forms prior to previewing/printing

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jlute@marzetti.com - 30 Jun 2008 14:48 GMT
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!!!
Dennis - 30 Jun 2008 15:33 GMT
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

> 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
[quoted text clipped - 6 lines]
>
> Thanks!!!
jlute@marzetti.com - 30 Jun 2008 16:34 GMT
Thanks, Dennis! That's a simple and nifty one!

> Dim i As Integer
> Dim strForm as String
[quoted text clipped - 21 lines]
>
> - Show quoted text -
Dirk Goldgar - 30 Jun 2008 15:50 GMT
>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
[quoted text clipped - 4 lines]
> 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 -----

Signature

Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

jlute@marzetti.com - 30 Jun 2008 16:37 GMT
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...@NOdataSPAMgnostics.com.invalid> wrote:
> <jl...@marzetti.com> wrote in message
>
[quoted text clipped - 52 lines]
>
> (please reply to the newsgroup)
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.