Link to home
Start Free TrialLog in
Avatar of wlwebb
wlwebbFlag for United States of America

asked on

Access - If CurrentProject.AllForms - problem closing form

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????????
ASKER CERTIFIED SOLUTION
Avatar of IrogSinta
IrogSinta
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

Avatar of wlwebb

ASKER

Good Grief.........