Hide Blank Fields

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Some time ago, someone in this forum suggested the following code to hide
controls which are blank:

Dim ctl As Control

For Each ctl In Me.GroupHeader0.Controls
Select Case Left(ctl.Name, 3)
Case "txt", "cbo"
If IsNull(ctl.Value) Then
ctl.Visible = False
Else
ctl.Visible = True
End If
Case Else
'Ignore: wrong type of control
End Select
Next ctl

However, I'm getting an error which says:

"Run-time error: '438': Object doesn't support this property or method.

Am I missing something here? Thanks.
ck
 
I expect that you have a label with a name that begins with "txt". A label
control will not have a Value property so this would generate the error you
see.
 
Thanks Duane. I didn't realize labels could begin with txt until now. I've
thought they are always named Label45 or something like this.
ck
 
If you are going to be writing code that references control names, then find
and use a good naming convention.
 
Much as I agree with that, Duane, I think in this case it would probably
make more sense to look at the type of the control rather than relying on
its name.

Dim ctl As Control

For Each ctl In Me.GroupHeader0.Controls
If TypeOf ctl Is TextBox or TypeOf ctl Is ComboBox Then
If IsNull(ctl.Value) Then
ctl.Visible = False
Else
ctl.Visible = True
End If
End If
Next ctl
 
Back
Top