Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Closing multiple forms!?!?

Status
Not open for further replies.

JaneB19

Technical User
Jun 27, 2002
110
GB
This might be really easy to do but I'm having a mental blank on how to go about it!

Is it possible to close multiple forms in 1 action and how?? I've tried creating a macro but it would only let me close one form at a time. Is this the one way I can do it?

Thanks
Jane
[PC2]
 
Here's your code:

Sub CloseAllForms(fPrompt as boolean)

Dim dbsCurrent As Database
Dim objTmp As Object
Dim strName As String

On Error GoTo CloseAllForms_ERR

If Not fPrompt Then
DoCmd.SetWarnings False
End If

Set dbsCurrent = CurrentDb()

' Get the forms
For Each objTmp In dbsCurrent.Containers("Forms").Documents
strName = objTmp.Name
If IsObjectOpen(acForm, strName) Then
DoCmd.Close acForm, strName
End If
Next objTmp

dbsCurrent.Close

CloseAllForms_EXIT:
If Not fPrompt Then
DoCmd.SetWarnings True
End If

Exit Function

CloseAllForms_ERR:
Resume CloseAllForms_EXIT

End Function


Function IsObjectOpen_TSB(intType As Integer, strName As String) As Boolean
' Determines if the object is open
IsObjectOpen_TSB = (SysCmd(acSysCmdGetObjectState, intType, strName) <> 0)

End Function


You call the CloseAllForms sub by:

'True to prompt for pending save,
'False to automatically save
CloseAllForms(False)
John Ruff - The Eternal Optimist :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top