Text box required based on combo box

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?
 
G

Guest

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
 
S

Storrboy

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...
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top