If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
closing all forms except main switchboard
My user needs me to provide a command button on every form that will close
all forms and return him to the main switchboard form. How do I do this? I was looking at the forms collection, but cant figure out how to do this as the count property of the forms collection is amended after each 'close'. Also I dont see the close method available. |
#2
|
|||
|
|||
Loop backwards through the Forms collection:
For i = Forms.Count - 1 to 0 Step -1 DoCmd.Close acForm Forms(i).Name End For Here's another approach. Paste the function below into a standard module. Set the On Close property of each form to: =Keep1Open([Form]) and the OnClose property of each report to: =Keep1Open([Report]) The function lets the user navigate from anywhere to anywhere, but opens the switchboard when no other form or report remains open and visible. Public Function Keep1Open(objMe As Object) On Error GoTo Err_Keep1Open 'Purpose: Open the Switchboard if nothing else is visible. 'Argument: The object being closed. 'Return: None. 'Usage: In the OnClose property of forms and reports: ' =Keep1Open([Form]) ' =Keep1Open([Report]) Dim sName As String 'Name of the object being closed. Dim lngObjType As Long 'acForm or acReport Dim bFound As Boolean 'Flag not to open the switchboard. Dim frm As Form 'an open form. Dim rpt As Report 'an open report. 'Initialize sName = objMe.Name If TypeOf objMe Is Form Then lngObjType = acForm ElseIf TypeOf objMe Is Report Then lngObjType = acReport End If 'Any other visible forms? For Each frm In Forms If frm.Visible Then If frm.Name sName Or lngObjType acForm Then bFound = True Exit For End If End If Next 'Any other visible reports? If Not bFound Then For Each rpt In Reports If rpt.Visible Then If rpt.Name sName Or lngObjType acReport Then bFound = True Exit For End If End If Next End If 'If none found, open the switchboard. If Not bFound Then DoCmd.OpenForm "frmSwitchboard" End If Exit_Keep1Open: Set frm = Nothing Set rpt = Nothing Exit Function Err_Keep1Open: If Err.Number 2046& Then 'OpenForm is not available when closing database. MsgBox "Error " & Err.Number & " - " & Err.Description End If Resume Exit_Keep1Open End Function -- Allen Browne - Microsoft MVP. Perth, Western Australia. Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. "gemma charters" gemma wrote in message ... My user needs me to provide a command button on every form that will close all forms and return him to the main switchboard form. How do I do this? I was looking at the forms collection, but cant figure out how to do this as the count property of the forms collection is amended after each 'close'. Also I dont see the close method available. |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Switchboard problems | Bob | Using Forms | 2 | July 29th, 2004 05:41 PM |
closing multiple forms | MC | Using Forms | 4 | July 26th, 2004 09:13 PM |
datasheet forms open in form mode from the Switchboard | Paul James | Using Forms | 5 | July 13th, 2004 06:51 AM |
Filter subform combobox on option button in main form | Emma | Using Forms | 1 | June 12th, 2004 12:24 AM |