Close All

G

Guest

Hello,

I was wondering what bit of code I might use to close all open forms,
reports, etc. but leave the database open. I have a timer that, upon
reaching 15 mins, currently boots a user from the system. However, I would
prefer if the timer instead closed all visible forms, then opened a log-on
form. Then, after another 45 mins of activity would timeout and close the
entire DB. However, I can't seem to figure out what to do programatically to
close all currently visible objects.

Thanks,

Vel
 
V

Van T. Dinh

Code from one of my databases:

********
Private Sub CloseLeftOverForms()
'================
' Form_frmMenu_Main.CloseLeftOverForms
'--------
' Purpose: To close Forms (except hidden frmLogIn & frmMenu_Main)
'--------
' Notes:
'--------
' Parameters:
' Cancel (Integer)
'--------
' Called Subs/Functions:
'--------
' Calling Subs/Functions:
'--------
' Returns:
'--------
' Author : Van T. Dinh, 20/03/2004
'--------
' Revision History
' 20/03/2004 (VTD): First-coded
'================

Const strFormsToRemain As String = "frmMenu_Main;frmLogIn"

Dim intCount As Integer
Dim intIndex As Integer
Dim frm As Access.Form

On Error GoTo CloseLeftOverForms_Err
intCount = Forms.Count
If (intCount > 2) Then
For intIndex = intCount - 1 To 0 Step -1
If (InStr(1, strFormsToRemain, Forms.Item(intIndex).Name) = 0) Then
DoCmd.Close acForm, Forms.Item(intIndex).Name, acSaveNo
End If
Next intIndex
End If

CloseLeftOverForms_Exit:
On Error Resume Next
Exit Sub

CloseLeftOverForms_Err:
Select Case Err.Number
Case 0
Case Else
MsgBox "Error " & Err.Number & ": " & Err.Description & vbCrLf &
vbCrLf & _
"(Programmer's note: Form_frmMenu_Main.CloseLeftOverForms)", _
vbOKOnly + vbCritical, "Run-time Error!"
End Select
Resume CloseLeftOverForms_Exit
End Sub
********
 
G

Guest

Here is a sub that will close all your open forms and reports. All you have
to do then is to open your login form. It will have to have a timer event to
take care of the 45 minutes.
 
D

Douglas J. Steele

Dim intLoop As Integer

For intLoop = (Forms.count - 1) To 0 Step -1
DoCmd.Close acForm, Forms(intLoop).Name, acSaveNo
Next intLoop
For intLoop = (Reports.count - 1) To 0 Step -1
DoCmd.Close acReport, Reports(intLoop).Name, acSaveNo
Next intLoop

Note that the acSaveNo refers to whether or not changes to the design of the
form or report will be saved, not whether data changes on the form will be
changed.
 
G

Granny Spitz via AccessMonster.com

Klatuu said:
Here is a sub that will close all your open forms and reports. All you have
to do then is to open your login form. It will have to have a timer event to
take care of the 45 minutes.

And the code is *fast* too! It's so fast it disappeared right before my eyes!
<g>
 
G

Guest

You're old and slow, Granny. Here it is again. I slowed it down for you :)

Public Sub CloseAll()
Dim frms As AllForms
Dim rpts As AllReports
Dim obj As Object

'Close Forms
Set frms = CurrentProject.AllForms
For Each obj In frms
If obj.IsLoaded Then
DoCmd.Close acForm, obj.Name, acSaveNo
End If
Next obj
'Close Reports
Set rpts = CurrentProject.AllReports
For Each obj In rpts
If obj.IsLoaded Then
DoCmd.Close acForm, obj.Name, acSaveNo
End If
Next obj

Set frms = Nothing
Set rpts = Nothing
Set obj = Nothing

End Sub
 
J

John Vinson

You're old and slow, Granny. Here it is again. I slowed it down for you :)

<CHORTLE>

I want to watch (from a safe distance) when the two of you meet in
real life...

John W. Vinson[MVP]
 
G

Guest

Granny is extra cool. I'm sure she wont take offense, but just in case, I
am changing my name, moving to another country, growing a beard, walking with
a limp, and wearing an eye patch.
 
G

Granny Spitz via AccessMonster.com

Klatuu said:
Granny is extra cool. I'm sure she wont take offense, but just in case, I
am changing my name, moving to another country, growing a beard, walking with
a limp, and wearing an eye patch.

When you take a sip of coffee and it tastes like flaming red hot chili
peppers, I want you to know it wasn't me ... this time. <g>
 
G

Guest

Wonder who it was last time?

Granny Spitz via AccessMonster.com said:
When you take a sip of coffee and it tastes like flaming red hot chili
peppers, I want you to know it wasn't me ... this time. <g>
 
J

John Vinson

When you take a sip of coffee and it tastes like flaming red hot chili
peppers, I want you to know it wasn't me ... this time. <g>

yum!!! Aztec Style... <going downstairs to make some salsa>

John W. Vinson[MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top