Try this:
'------ start of revised code ------
Private Sub Form_Current()
Dim ctl As Control
For Each ctl In Me.Controls
If Not TypeOf ctl Is Label Then 'omit labels
Me.Controls("lbl" & ctl.Name).Visible = Not IsNull(ctl)
End If
Next ctl
End Sub
'------ end of revised code ------
That should hide the label if the control is null, and hide the label if it
isn't.
--
Dirk Goldgar, MS Access MVP
Access tips:
www.datagnostics.com/tips.html
(please reply to the newsgroup)
"alex" <(E-Mail Removed)> wrote in message
news:5c84253e-ba3a-40a7-a376-(E-Mail Removed)...
Assign string to control
Hello,
Using Access 03
Im attempting to convert a string name to a control nameHeres the
code:
Private Sub Form_Current()
Dim ctl As Control
For Each ctl In Me.Controls
If Not TypeOf ctl Is Label Then 'omit labels
If IsNull(ctl) Then 'if no value
Dim strLabel As String
strLabel = "Me.lbl" & (ctl.Name)
strLabel.Visible = True does not work!
'Debug.Print (strLabel)
Else
End If
End If
Next ctl
End Sub
All of my labels have an lbl prefix. If the ctl is null, Id like
to concatenate the lbl in front of (ctl.name) and hide the label.
It seems to work (at least the name) in the immediate window.
I cant get Access to recognize the control, however.
Keep in mind that my labels are NOT linked to my textboxes et al. I
did this because I place the label on top of the textbox to save
space. If the textbox is empty, the label is displayed. If not, the
textbox value appears. This only seems to work when the label and
texbox are not linked.
Thanks,
alex