?
Solved

Access - If CurrentProject.AllForms - problem closing form

Posted on 2012-09-05
3
Medium Priority
?
631 Views
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????????
0
Comment
Question by:wlwebb
3 Comments
 
LVL 29

Accepted Solution

by:
IrogSinta earned 2000 total points
ID: 38370557
Try moving line 12 to line 6 instead.
0
 
LVL 66

Expert Comment

by:Jim Horn
ID: 38370615
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

0
 

Author Closing Comment

by:wlwebb
ID: 38370633
Good Grief.........
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

862 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