Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code to look for empty fields

Status
Not open for further replies.

3699wat

Technical User
Sep 30, 2002
28
US
I am using the following code to set a label to invisible if the textbox is empty. It works great for each textbox / label on the report, but the problem is that I have to set it for each one.


If Me.Textbox = “ “ or IsNull (Me.Textbox) Then
Me.Label.Visible = False
Else
Me.Label.Visible = True
End If

Is there an expression / code that would loop through the fields and set all labels to invisible if the textbox is empty?

 
Hi!

You will have to name the text boxes and labels appropriately (which should be done anyway) but, if you do, then you can use the following code:

Dim cntl As Control
Dim strLabel As String

For Each cntl In Me.Controls
If cntl.ControlType = acTextBox Then
If Nz(cntl.Value, "") = "" Then
strLabel = "lbl" & Mid(cntl.Name, 4)
Me.Controls(strLabel).Visible = False
End If
End If
Next cntl

Obviously you will need to match up the names of the text boxes and labels. If the text box is txtName then the label needs to be lblName.

hth
Jeff Bridgham
bridgham@purdue.edu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top