Access - If CurrentProject.AllForms - problem closing form

Posted on 2012-09-05
Last Modified: 2012-09-05
Hello all

Probably another stupid typo but I've checked everything and even copy and pasted names of the form so I wouldn't have a typo.......

I have a Form, when I click the Save control button I have code that looks for other open but hidden forms and makes them visible and then thought it would close the form.....

It works at making the hidden form visible........BUT.......
I can't get it to close the original form??????

Private Sub cmdSaveCtlTotals_Click()
    dblCtlTtlAmtIn = Me.txtCtlAmtIn
    dblCtlTtlAmtOut = Me.txtCtlAmtOut
    dblCtlTtlNetAmt = Me.txtCtlNetAmt
    dblCtlTtlAmtVal = Me.txtCtlAmtVal
    If CurrentProject.AllForms("frm_ClearChipSelectMachines").IsLoaded Then
        Forms!frm_ClearChipSelectMachines.Visible = True
    End If
    If CurrentProject.AllForms("frm_ShiftReportingLVL").IsLoaded Then
        DoCmd.Close , "frm_LVLReportingControlTotals"
        Forms!frm_ShiftReportingLVL.Visible = True
    End If
    ' DoCmd.Close , "frm_LVLReportingControlTotals"
End Sub

Open in new window

As you can tell it's the
DoCmd.Close , "frm_LVLReportingControlTotals"

I've tried it without quotations, I've tried it without quotations and Forms!.....

It unhides the frm_ShiftReportingLVL alright but puts the form I'm trying to close in the background behind the Form made visible and just leaves it open.........

Where am I messing up????????
Question by:wlwebb
    LVL 29

    Accepted Solution

    Try moving line 12 to line 6 instead.
    LVL 65

    Expert Comment

    by:Jim Horn
    Here's a sub I built (stole?) awhile tack to close every open form, except for the form that's passed in the parameter FormName .

    Public Sub sb_close_all_open_forms(Optional FormName As String)
    'Closes all open forms and reports except the form specified by the FormName parameter.
    On Error Resume Next
    Dim int_open_forms As Integer                ' Number of open forms.
    Dim i As Integer
    ' Close all open forms.
    int_open_forms = Forms.Count         'Number of open forms.
    For i = int_open_forms - 1 To 0 Step -1
        If Forms(i).Name <> FormName Then
            DoCmd.Close A_FORM, Forms(i).Name
        End If
    Next i
    End Sub

    Open in new window


    Author Closing Comment

    Good Grief.........

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
    Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now