Results 1 to 8 of 8
  1. #1
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276

    Close All Open Forms & Open SwitchBoard From

    I am using the following module is there a simple way that I dont have to mention each and every form to close the open forms and open SWITCHBOARD






    Option Compare Database


    '------------------------------------------------------------
    ' Close_All
    '
    '------------------------------------------------------------
    Function Close_All()
    On Error GoTo Close_All_Err


    DoCmd.OpenForm "SWITCHBOARD", acNormal, "", "", acAdd, acNormal
    DoCmd.Close acForm, "AcTitleFrm"
    DoCmd.Close acForm, "PurchaseFRM"
    DoCmd.Close acForm, "SalesFRM"
    DoCmd.Close acForm, "Form For Purchase Dept Reports"
    DoCmd.Close acForm, "Company Accounts"
    DoCmd.Close acForm, "Challan"
    DoCmd.Close acForm, "Invoice"
    DoCmd.Close acForm, "Payments"
    DoCmd.Close acForm, "Items Form"
    DoCmd.Close acForm, "Stock Report Sales & Purchase"
    DoCmd.Close acForm, "FORMS SWITCH"
    DoCmd.Close acForm, "switch reprts"




    Close_All_Exit:
    Exit Function


    Close_All_Err:
    MsgBox Error$
    Resume Close_All_Exit


    End Function

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    5,032
    Google tells me there is. Close all forms, THEN open the required form last.
    https://www.google.com/search?q=clos...hrome&ie=UTF-8
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276
    I used the following function, it works I added

    DoCmd.OpenForm "SWITCHBOARD", acNormal, "", "", acAdd, acNormal

    to the code, please tell me if its done correctly.




    Function CloseFrms(Optional strExcept As String)

    Dim I As Integer
    With Application.Forms
    For I = .Count - 1 To 0 Step -1
    With .Item(I)
    If .Name <> strExcept Then
    DoCmd.Close acForm, .Name
    End If
    End With
    Next I
    End With
    DoCmd.OpenForm "SWITCHBOARD", acNormal, "", "", acAdd, acNormal
    End Function

  4. #4
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,436
    DoCmd.OpenForm "SWITCHBOARD", acNormal, "", "", acAdd, acNormal
    Keep it simple. Below is probably sufficient.

    DoCmd.OpenForm "SWITCHBOARD"

  5. #5
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276
    Quote Originally Posted by aamer View Post
    I used the following function, it works I added

    DoCmd.OpenForm "SWITCHBOARD", acNormal, "", "", acAdd, acNormal

    to the code, please tell me if its done correctly.




    Function CloseFrms(Optional strExcept As String)

    Dim I As Integer
    With Application.Forms
    For I = .Count - 1 To 0 Step -1
    With .Item(I)
    If .Name <> strExcept Then
    DoCmd.Close acForm, .Name
    End If
    End With
    Next I
    End With
    DoCmd.OpenForm "SWITCHBOARD", acNormal, "", "", acAdd, acNormal
    End Function



    You Mean Like This



    Function CloseFrms(Optional strExcept As String)

    Dim I As Integer
    With Application.Forms
    For I = .Count - 1 To 0 Step -1
    With .Item(I)
    If .Name <> strExcept Then
    DoCmd.Close acForm, .Name
    End If
    End With
    Next I
    End With
    DoCmd.OpenForm "SWITCHBOARD"

    End Function

  6. #6
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,436
    Function CloseFrms(Optional strExcept As String)

    Dim I As Integer
    With Application.Forms
    For I = .Count - 1 To 0 Step -1
    With .Item(I)
    If .Name <> strExcept Then
    DoCmd.Close acForm, .Name
    End If
    End With
    Next I
    End With
    DoCmd.OpenForm "SWITCHBOARD"

    End Function
    Well, yes. Have you tried it?

  7. #7
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,840
    This can be simpler (i.e. don't have to worry about index)
    Code:
    Function CloseAllForms()
    Dim obj As AccessObject
    
    For Each obj In CurrentProject.AllForms
       If obj.IsLoaded Then DoCmd.Close acForm, obj.Name
    Next
    DoCmd.OpenForm "FormNameHere"
    
    End Function
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276
    thank you worked like a charm

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Error 2001 on Switchboard Open
    By mib1019 in forum Forms
    Replies: 1
    Last Post: 06-16-2020, 03:07 PM
  2. Open Form From Switchboard show on another Tab
    By billgyrotech1 in forum Access
    Replies: 6
    Last Post: 06-07-2019, 02:22 PM
  3. Switchboard on Open Database
    By 1937 in forum Forms
    Replies: 1
    Last Post: 01-28-2017, 01:58 PM
  4. Replies: 2
    Last Post: 08-07-2013, 07:44 AM
  5. Replies: 1
    Last Post: 05-03-2012, 02:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums