?
Solved

Mother form closes when daughter form goes in design mode.

Posted on 2011-10-19
21
Medium Priority
?
395 Views
Last Modified: 2012-05-12
I have a mother form with a number of controls on which each opens a different daughter form, finding specific detail. See On open code for mother form below.

When I open a daughter form and then goes to desihn mode, the mother form closes. Can anybody tell me why?

Normally, if I do not go into design mode witrh the daughter, and I close her, the mother stays open.


Private Sub OpenID100_Click()
'Opens ID100 form to add or edit
    Dim stDocName As String
    Dim stLinkCriteria As String
   
     stDocName = "frmID100"
   
    stLinkCriteria = "[Calls_at_PortID]=" & Me![Calls_at_PortID]
    DoCmd.OpenForm stDocName, , , stLinkCriteria

End Sub
0
Comment
Question by:Fritz Paul
  • 7
  • 5
  • 4
  • +2
21 Comments
 
LVL 77

Expert Comment

by:peter57r
ID: 36991743
Do you have code in the daughter form Close or Unload events?
0
 
LVL 61

Expert Comment

by:mbizup
ID: 36991749
I am guessing there is some code in the daughter form's (frmID100) close event that is making this happen
0
 
LVL 61

Expert Comment

by:mbizup
ID: 36991750
Yikes - I'm posting slow today.  Sorry about that, Pete :)
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 77

Expert Comment

by:peter57r
ID: 36991866
Hi Miriam
I find it reassuring when someone else has the same thought!
0
 

Author Comment

by:Fritz Paul
ID: 36992051
I have code in
On Load
Before Update
On Activate
Should I include the code for you? The mother form closes immediately when I go into design mode with the daughter form.
0
 
LVL 77

Expert Comment

by:peter57r
ID: 36992076
You might as well post the code.
0
 

Author Comment

by:Fritz Paul
ID: 36992552
Here is the whole form's code. Thanks for the effort.

Option Compare Database

Private Sub Form_Activate()
    Me.Refresh
    Vessel_Change

End Sub



Private Sub Form_BeforeUpdate(Cancel As Integer)
    DataUpdate

End Sub

Private Sub Form_Load()
    ci_CenterIt Me, True, 3
    SetCondForm
End Sub

Private Sub Vessel_Change()
On Error GoTo Err_Vessel_Change

    Portofregistry = DLookup("[PortOfRegistry]", "[tblVessel]", "[VesselID]=Vessel.Value")
    VesselOwner = DLookup("[VOwner]", "[tblVessel]", "[VesselID]=Vessel.Value")
    VoyageNo = DLookup("[VoyageNo]", "[tblVessel]", "[VesselID]=Vessel.Value")
    Deadweight = DLookup("[Deadweight]", "[tblVessel]", "[VesselID]=Vessel.Value")
    Callsign = DLookup("[Callsign]", "[tblVessel]", "[VesselID]=Vessel.Value")
    LOA = DLookup("[LOA]", "[tblVessel]", "[VesselID]=Vessel.Value")
    Beam = DLookup("[Beam]", "[tblVessel]", "[VesselID]=Vessel.Value")
    Registeredtonnage = DLookup("[GRT]", "[tblVessel]", "[VesselID]=Vessel.Value")
    IMOShipNo = DLookup("[IMOShipNo]", "[tblVessel]", "[VesselID]=Vessel.Value")
    TypeOfVessel = DLookup("[TypeOfVessel]", "[tblVessel]", "[VesselID]=Vessel.Value")
    NRT = DLookup("[NRT]", "[tblVessel]", "[VesselID]=Vessel.Value")
    NationalityOfVessel = DLookup("[NationalityOfVessel]", "[tblVessel]", "[VesselID]=Vessel.Value")

   
Exit_Vessel_Change:
    Exit Sub

Err_Vessel_Change:
    MsgBox Err.Description
    Resume Exit_Vessel_Change
       
End Sub

Private Sub Command102_Click()
On Error GoTo Err_Command102_Click

    Dim stDocName As String

    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70


    stDocName = "rptID100"
'    DoCmd.OpenReport stDocName, acPreview
    stLinkCriteria = "[Calls_at_PortID]=" & Me![Calls_at_PortID]

    DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria

Exit_Command102_Click:
    Exit Sub

Err_Command102_Click:
    MsgBox Err.Description
    Resume Exit_Command102_Click
   
End Sub
Private Sub cmdClose_Click()
On Error GoTo Err_cmdClose_Click

   
    DataUpdate

   
    If Me.Dirty Then
        RunCommand acCmdSaveRecord
    End If
   
    DoCmd.Close



Exit_cmdClose_Click:
    Exit Sub

Err_cmdClose_Click:
    MsgBox Err.Description
    Resume Exit_cmdClose_Click
   
End Sub


Private Sub ctlOpenfrmtblVessel_Click()
On Error GoTo Err_ctlOpenfrmtblVessel_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "frmtblVesselForID100"
   
    stLinkCriteria = "[VesselID]=" & Me![Vessel]
    DoCmd.OpenForm stDocName, , , stLinkCriteria
   
    Forms.frmtblVesselForID100.cboFindRecord.Value = Me![Vessel].Value
    Forms.frmtblVesselForID100.cboFindRecord.Enabled = False


Exit_ctlOpenfrmtblVessel_Click:
    Exit Sub

Err_ctlOpenfrmtblVessel_Click:
    MsgBox Err.Description
    Resume Exit_ctlOpenfrmtblVessel_Click
   
End Sub

Private Sub DataUpdate()
On Error GoTo Err_DataUpdate

    Dim ctl As Control
    Me.CompleteDat.Value = 0
    For Each ctl In Me.Controls
        If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Then
            If IsNull(ctl) = True Then
                CompleteDat.Value = CompleteDat.Value - 1
            End If
        End If
    Next

Exit_DataUpdate:
    Exit Sub

Err_DataUpdate:
    MsgBox Err.Description
    Resume Exit_DataUpdate

End Sub

Private Sub SetCondForm()
'Sets the conditional formatting of each control which "Is Null" to
'                                               BackColor = 12615935
Dim fc As FormatCondition, ctl As Control

    For Each ctl In Me.Controls
      If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Then
        With ctl.FormatConditions
          If .Count = 0 Then
            Set fc = .Add(acExpression, , "[" & ctl.Name & "] is Null")
            fc.BackColor = 14465535
          End If
        End With
      End If
    Next
   
End Sub

0
 
LVL 61

Expert Comment

by:mbizup
ID: 36992760
I doubt this will affect your design view issue, but you should change this line in your cmdClose_Click event code:

>>     DoCmd.Close

To:

Docmd.close acform, me.name

This will ensure that the correct object gets closed.  Simply using Docmd.Close without specifying a particular object is not always reliable.

I don't see anything in particular in that code that would affect design view.  Can you upload a sample copy of your database (with any sensitive data masked or removed).
0
 

Author Comment

by:Fritz Paul
ID: 36993627
Hi,

Thanks for the tip.

I uploaded the zip file to http://dl.dropbox.com/u/20169294/Wes_Kus.zip .

At the moment this is only uncomfortable during development, but there might emerge some problem in operation. I will understand if this is becoming a too large job.

Menu 2.2.1 opens the mother form.
Choose any vessel Name.
Second button flom left named   ID100   opens ID100 form.
When you go into design mode, the mother form closes.
Then you need to select menu 2.2.1 again.

0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 36995585
Can you upload a "Simple" db that demonstrates this issue...?

This all works fine for me in the attached sample.

Are you sure the "mother form" is not just "Behind" the popup form, hence it is "Hidden" and not really "Closed?

JeffCoachman
Database48.mdb
0
 
LVL 61

Accepted Solution

by:
mbizup earned 2000 total points
ID: 36996389
Here's the issue - it makes complete sense, but it is one I have never run across before :-)

You have a subform called "frmtblComments" that is present on both the mother and daughter forms.

When you change your daughter form to design view, the mother form automatically closes.  There is no code or anything else that you have added to cause this.

It is simply because that subform (a single object) cannot be open in design view and form view at the same time.

You could redesign your forms to use two different subforms.

Alternatively, you could add code to close the mother form before opening the daughter form and  code in the daughter form to reopen the mother form when closing the daughter form.  This is a very common approach.

The code would change like this:

Private Sub OpenID100_Click()
'Opens ID100 form to add or edit
    Dim stDocName As String
    Dim stLinkCriteria As String
    
     stDocName = "frmID100"
    
    stLinkCriteria = "[Calls_at_PortID]=" & Me![Calls_at_PortID]
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    DoCmd.Close acform, me.name

End Sub 

' and add a close event to your D100 form

Private Sub Form_Close()
       Docmd.OpenForm "frmProcWIPVessel"
End Sub

Open in new window


0
 
LVL 75
ID: 36996415
Yep ... I JUST discovered that also ... and really, there was no other explanation !  I remmed out all code everywhere ... no changed.  Then I noticed that subform on both forms! Bingo!

mx
0
 
LVL 61

Expert Comment

by:mbizup
ID: 36996590
Actually - scrap the idea of reopening the mother form in the close event of the daughter form altogether.  THAT will cause problems of its own.

Your best options are:

1 - redesign your forms to use two different (but similar subforms)

or

2 - Live with the solution you have (the only issue is inconvenience to you when switching to design view)

My own preference would be 1) redesigning the forms with seperate subforms.
0
 
LVL 75
ID: 36996657
I vote for #1 because that is such a simple form.

Another thing you could do ... in order to have just one physical subform ... would maybe be to use the Activate/DeActivate to Set/Clear the Subform control Source Object, such that only one is in effect at a time.

mx
0
 
LVL 75
ID: 36996723
ok ... try the attached db.  I added the code to the Activate/DeActivate events ... and that seems to resolve the problem ... going to Design view - and having the other form close.

mx
Wes-Kus37-MX01.zip
0
 

Author Closing Comment

by:Fritz Paul
ID: 36998645
Thanks a lot. This was something that was worrying me a long time. I kept on looking past the cause.
The reason why I chose the duplicate form solution above the activate/deactivate solution, which works perfectly, is that in this case I only need to make one duplicate and change only my mother form.
0
 

Author Comment

by:Fritz Paul
ID: 36998662
I want a last word.
You people impress me tremendously.
I espacially appreciate the trouble that you go to.
DatabaseMX even changed the forms and submitted the for me to test.
He had a very nice solution, but was more work to implement and the simpler method of two subforms were chosen.
I learnt a lot.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 36998742
Glad to help out, and thanks for the good words - it was a nice way to start the day. :)
0
 
LVL 75
ID: 37001086
"but was more work to implement and the simpler method of two subforms were chosen."
Seriously?  4 lines of code compared to another subform ?

mxd
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 37001524
mbizup,

You seem to be on stEEroids lately...

;-)
0
 
LVL 61

Expert Comment

by:mbizup
ID: 37001576
Lol!
0

Featured Post

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Suggested Courses

749 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