Using check box to make text field enable or unenable

vividor

Registered User.
Local time
Today, 06:53
Joined
Aug 5, 2002
Messages
31
I have a text field that I would like to be enable when a certain check box is checked and unenable when the box is not checked. Any help would be appreciated. Thanks.
 
If MyCheckBox = True then
MyControl.Enabled = True
Else
MyControl.Enabled = False
End if

You can 'shorten' this

MyControl.Enabled = (MyCheckBox = True)

since (MyCheckBox = True) evaluates to True or False

or even

MyControl.Enabled = MyCheckBox

The shorter versions are 'cleverer' and quicker (although in most circumstances the difference in speed is irrelevant) but are not so 'transparent' (i.e. it is more obvious what the first version is doing).

There might be occasions when clarity is more important than efficiency. Take your pick.

Jeff

ps. You can use .Locked instead of .Enabled. Try both to see the difference.
 
MyControl.Enabled = MyCheckBox

might have to be
MyControl.Enabled =Nz(MyCheckBox)
 
thank you guys for the answer...
I only have couple of questions, where should I place those instructions? the text field or check box and where in the text field, check box(properties?)
 
You'll probably need the code in two places:

The On Current event for the form so that you enable/disable your field as you move from one record to another (assuming single forms view).

The After Update event for the check box.

Jeff
 
Hey guys, I am kind of loss with all those instructions...
My Problem is more simple that the comments of the other guy..
I got a check box named "New Page" and belog that a field text "Comments". I want to enable the text field "comments" when I click on the check box "New Page, in the mean time the text field should ne disable...
 
OK on the property sheet for the form current select [Event Procedure], click the button with three dots beside it to open the module window it'll say
Private Sub Form_Current()
End Sub


type in between the two lines so that it looks like
Private Sub Form_Current()
IfMe.[New Page]=True Then
Me.Comments.Enabled=True
Else
Me.Comments.Enabled=False
End If
End Sub
follow the same method for the after update event of New Page
it should look like
New_Page_Click()
Form_Current
End Sub
you have to type in Form_Current
remember to select compile and save all modules from the menu bar
 

Users who are viewing this thread

Back
Top Bottom