How do I disable a field based oninput of another field?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am working on a form and want to be able to disable a field based on a
combo box selection. (example: I have a combo box that has a yes, no option
and for the yes I require a comment box to be complete, but for no I want to
disable it so they can skip right over it - or if there is another way to do
it where the field doesn't even show unless they chose yes.)
 
Lisa,
Make the field (ex name Field1) Visible = No.
Using the AfterUpdate event of your combo (ex name cboMyCombo)
If cboMyCombo = "Yes" Then
Me.Field1.Visible = True
Else
Me.Field1.Visible = False
End If

You'll also have to add that exact same code to the form's OnCurrent
event, so that each time you visit a record, Field1 will show or not show.
Visible = False, in effect, "disables" the field.
hth
Al Camp
 
In the after update event of the combo box (and in the on current event of
the form) put the following code.
If ComboBoxName = "Yes" then
CommentBoxName.Enabled = True
else
CommentBox.Enabled = False
end if
 
You would actually be enabling/disabling the control (text box, for instance)
rather than the field. One way to accomplish your aim would be to use the
form's Current event to set the comment text box (I will call it txtComment)
visible property to False. To do this, open the form in design view, and
click View > Properties. You could also see the form's properties by double
clicking the little box within a box at the top right near where the rulers
would intersect. Once the property sheet is open, click the Event tab.
Click Current, click the three dots, click Code Builder, and click OK. Where
the cursor is blinking add the following lines of code:

If IsNull me.txtComment Then
me.txtComment.Visible = False
Else: me.txtComment.Visible = True
End If

Similarly, you would see the combo box (I will call it cboYesNo) properties
by clicking to select, then clicking View > Properties; or you could double
click the combo box. Always in form Design View for this stuff. In the
After Update event for cboYesNo, add the following line of code:

If me.cboYesNo = "Yes" Then
me.txtComment.Visible = True
End If

Use the actual names for your combo box and text box, of course.
 
Back
Top