Link to home
Start Free TrialLog in
Avatar of Fritz Paul
Fritz PaulFlag for South Africa

asked on

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
Avatar of peter57r
peter57r
Flag of United Kingdom of Great Britain and Northern Ireland image

Do you have code in the daughter form Close or Unload events?
I am guessing there is some code in the daughter form's (frmID100) close event that is making this happen
Yikes - I'm posting slow today.  Sorry about that, Pete :)
Hi Miriam
I find it reassuring when someone else has the same thought!
Avatar of Fritz Paul

ASKER

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.
You might as well post the code.
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

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).
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.

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
ASKER CERTIFIED SOLUTION
Avatar of mbizup
mbizup
Flag of Kazakhstan 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
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
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.
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
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
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.
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.
Glad to help out, and thanks for the good words - it was a nice way to start the day. :)
"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
mbizup,

You seem to be on stEEroids lately...

;-)
Lol!