Logo

My Access Tips for Custom Microsoft Access

Application Development

by Matthew V Carmichael


Need Help?

My Tips


Links

Resources
Quick Tip Details
Question:
How do I hide a specific Textbox control on a Report if the no data is present (Null Value).
Answer:
Create a procedure from the OnFormat event to loop through the controls and change the visible property if null. This can also be accomplished on a Form by executing the code from the OnCurrent event.
Code:
‘For a Report
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    Dim ctl As Control
    
    For Each ctl In Me.Report
        If ctl.ControlType = acTextBox Then
            ctl.Visible = Not IsNull(ctl.Value)
        End If
    Next ctl

End Sub
  -------------------------------------------------------------------------------
‘For a Form
Private Sub Form_Current()

    Dim ctl As Control
    
    For Each ctl In Me.Form
        If ctl.ControlType = acTextBox Then
            ctl.Visible = Not IsNull(ctl.Value)
        End If
    Next ctl

End Sub