Text box required based on combo box

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

Guest

I have a combobox with multiple selections (lets say A, B, C) and a blank
text box. When the user selects "B" from the combo box, I would like to make
the text box required. Can anyone help?
 
Use the afterUpdate event of the combo box to check and enable disable the
textbox

Try something like:

If me.ComboboxName="B" then
Me.TextboxName.Enabled=True
Else
Me.TextboxName.Enabled=False
End If
 
Cabgolfer said:
I have a combobox with multiple selections (lets say A, B, C) and a blank
text box. When the user selects "B" from the combo box, I would like to make
the text box required. Can anyone help?

When would you need to know that it's required? When the form tries to
update the record? Before a selection in another control is made? If the
field in the underlying table is only required in some conditions, then
you'll need to determine when the check should be done and see if the
textbox contains a value. With more detail from you I could be more
specific, but in essence you would use the following in some event of the
form or other control....

If Nz(Me![TextBoxName],"")="" Then MsgBox "This box is required"

What happens after that depends on the unknown circumstances. Should it
prevent moving to another control? Cancel the update of the record? And so
on...
 
Use the BeforeUpdate event of the form to check the values in the control,
and prompt a message incase the values are not filled.

Something like

If Me.[ComboName] = "B" And IsNull(Me.[TextBoxName] ) Then
Msgbox "Text box must be filled"
Me.[textBoxName].SetFocus ' will move the cursor to the text box
Cancel = True ' will stop the save from continue
End If
 
Back
Top