Disabling controls at runtime.

  • Thread starter Thread starter michael.galvin
  • Start date Start date
M

michael.galvin

Guest
Hi all

This has been driving me nuts all day! I have a form with 15 text boxes (acting as labels) and 15 text boxes (acting as themselves) on it. The 'caption' of the label textboxes comes from a table (as does the value of the text boxes) but if the caption is empty, I want to either disable or make invisible the corresponding text box.

I assume the following code would work (I'm a VBer by trade - working in Access was not my idea
wink.gif
)

If Len(Trim(label1.Value)) = 0 Then
text1.Visible = False
End If

and I'm sure it would but I can't figure out where to put it. I get a range of errors (the current one is about a property name that MA can't find). I tried label1.text, and I got the usual guff about not being able to use that property unless the control has focus, which kinda defeats the purpose.

Can anyone help me disable controls at runtime?
 
Try the following:

If IsNull(Me.label1) Then
Me.text1.Visible = False
Else
Me.text1.Visible = True
End If

You will need to trigger the code using the form's "On Current" event.

HTH
RDH
 
You, sir, are a genius
smile.gif


I'll be back here when I have more problems (it seems to be one of the better Access boards around...)
 
You are very welcome Michael ..... :-)
I am glad it worked for you.

RDH
 

Users who are viewing this thread

Back
Top Bottom