Access Reference

Hide a subform if the main form contains no records

Direct Answer

Hide a subform if the main form contains no records
is part of the Access VBA object model. This reference page documents its syntax, parameters, and typical usage.

Reference

The following example illustrates how to hide a subform named _Orders_Subform_ if its main form does not contain any records. The code resides in the main form’s Current event procedure.

“`vb
Private Sub Form_Current()

With Me![Orders_Subform].Form

‘ Check the RecordCount of the Subform.
If .RecordsetClone.RecordCount = 0 Then

‘ Hide the subform.
.Visible = False

End If
End With
End Sub
“`

!include[Support and feedback]

Reference: Access object-model documentation • updated 09/21/2018
. Rebuilt for readability; see the original for complete parameter matrices.