Hide subform with zero linked records?

fraser_lindsay

Access wannabe
Local time
Today, 15:53
Joined
Sep 7, 2005
Messages
218
Hi,

I have a form with one subform. I can hide and siaply the subform using this code in my AfterUpdate event of the checkbox, that works:


Private Sub chkRestrictionApplied_AfterUpdate()

If Me.chkRestrictionApplied Then
Me.tblRestrictions_Subform.Enabled = True
Else: Me.tblRestrictions_Subform.Enabled = False
End If

If Me.chkRestrictionApplied Then
Me.tblRestrictions_Subform.Visible = True
Else: Me.tblRestrictions_Subform.Visible = False
End If


End Sub



But then I realised that ideally I woudl want to click that tab control and if records are already attached to the parent then the subform should display them. Otherwise you can uncheck the box and the form disappears even though records are present.

I have tried this code in the 'on click' event of the particular tab but it doesn't seem to work.


Private Sub Medical_Restrictions_Click()

If Me.tblRestrictions_Subform.RecordsetClone.RecordCount = 0 Then
Me.tblRestrictions_Subform.Visible = False
Else: Me.tblRestrictions_Subform.Visible = True

End If

End Sub



I'd like the subform hidden, then visible when the user checks the box next to 'I want to add a restriction' and then visible at all times that a record (restriction) has been added.


Any help would be greatly appreciated, as ever.

Thanks
 
Assuming that the name of your SubFormControl is tblRestrictions_Subform then try:
If Me.tblRestrictions_Subform.FORM.RecordSet.RecordCount = 0 Then
... you know you are looking at the SubFormControl when the Data tab has the LinkChild/MasterFields properties on it. The SubFormControl need not be named the same as the Form it displays.
 
Last edited:
Job done. Another minor step forward.

Thanks for your help.
 

Users who are viewing this thread

Back
Top Bottom