Disable/Enable field until check box is selected/deselected

Will04

Registered User.
Local time
Today, 15:31
Joined
May 29, 2006
Messages
62
Hi everyone,

I've got some check boxes on a form which includes one for 'Other'. Whenever the 'Other' check box is checked (selected) I want to display a text box in which the user can specify what 'Other' means.

This works fine with the following code:-

'****
Private Sub MHOther_Click()
Me.MHOthSpecify.Enabled = True
End Sub
'****
However, if I should de-select the 'Other' check box, the text box still remains visible with its contents.

I would like to clear the contents and disable the text box when the check box is unchecked.

Any Suggestions??


Appreciated

Will
 
Use an if/then on the value of the checkbox. If true, enable it, otherwise clear and disable.
 
Thanks Paul..

I used the following code, which works just fine..
'---------------------------------
Private Sub MHOther_Click()
If Me![MHOther] = True Then
Me.MHOthSpecify.Enabled = True
Forms!CSMainfrm!MHOthSpecify.SetFocus

Else
Me.MHOthSpecify.Enabled = False
Me.MHOthSpecify = " "
End If
'--------------------------------------

How can I force to user to enter a value in the text box 'MHOthSpecify' i.e. once the 'Other' check box is selected, the user MUST enter a value in the text box or a message will be displayed and control should remain at the text box.

Thanks

Will
 
That's the kind of validation I normally do behind the main "save" button on the form, or in the before update event of the form (since it can be canceled). In my experience, many users like to jump around in a different order than I anticipate, and forcing them to do a certain control at a certain point just upsets them.
 
Paul,

I'm sure that some users may choose to 'jump around' the form, but what I'm trying to do is when or if they do select 'Other', I want to ensure that some value is entered in the text box that is enabled. In other words, you can't (shouldn't) have 'Other' selected and this text box remain blank.

How can I do this.

Thanks

Will
 
Oh I understand, I would just do it when I described rather than locking them in that control. The test is simple:

If Me.Checkbox = True and Len(Me.Textbox & vbNullString) = 0 Then
...

BTW, be careful as in your code above you don't empty the textbox, you put a space in it. I'd either set it to Null or "".
 
Thanks a Mill.

Hi Paul,

Thanks so much for the help. I'll try it and give you a feedback..

Once again, many thanks..


Appreciated,

Will
 

Users who are viewing this thread

Back
Top Bottom