Mother form closes when daughter form goes in design mode.

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
Fritz PaulAsked:
Who is Participating?
 
mbizupConnect With a Mentor Commented:
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
 
peter57rCommented:
Do you have code in the daughter form Close or Unload events?
0
 
mbizupCommented:
I am guessing there is some code in the daughter form's (frmID100) close event that is making this happen
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
mbizupCommented:
Yikes - I'm posting slow today.  Sorry about that, Pete :)
0
 
peter57rCommented:
Hi Miriam
I find it reassuring when someone else has the same thought!
0
 
Fritz PaulAuthor Commented:
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
 
peter57rCommented:
You might as well post the code.
0
 
Fritz PaulAuthor Commented:
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
 
mbizupCommented:
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
 
Fritz PaulAuthor Commented:
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
 
Jeffrey CoachmanMIS LiasonCommented:
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
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
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
 
mbizupCommented:
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
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
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
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
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
 
Fritz PaulAuthor Commented:
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
 
Fritz PaulAuthor Commented:
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
 
mbizupCommented:
Glad to help out, and thanks for the good words - it was a nice way to start the day. :)
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
"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
 
Jeffrey CoachmanMIS LiasonCommented:
mbizup,

You seem to be on stEEroids lately...

;-)
0
 
mbizupCommented:
Lol!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.