View Full Version : Disabling controls at runtime.


michael.galvin
07-14-2001, 10:15 AM
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 http://www.access-programmers.co.uk/ubb/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?

R. Hicks
07-14-2001, 01:34 PM
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

michael.galvin
07-14-2001, 01:54 PM
You, sir, are a genius http://www.access-programmers.co.uk/ubb/smile.gif

I'll be back here when I have more problems (it seems to be one of the better Access boards around...)

R. Hicks
07-14-2001, 02:05 PM
You are very welcome Michael ..... :-)
I am glad it worked for you.

RDH