Enabling a field based on a combo box

G

Guest

I have created a combo box with 5 drop down choices. I want a date to be
enabled if the user chooses 3 out of the five choices, otherwise i want the
date field to be disabled. I know how to do this for a yes/no combo box, but
not if there is more than one choice. Any advice would be greatly appreciated!
 
A

Al Camp

I'm going to assume that your using a Value List for your combo...

1. You could just set up a CaseSelect that would evaluate the combo
selection, and enable or disable accordingly. Check out Help on how to set
up a CaseSelect... it's pretty straight forward, and eassier to set up for a
newbie than a "nested" IIF statement.

2. The next solution would be to make the combo two columns. The first
column would be the value you want to select, the second would be a Yes or
No accordingly. Your value list would look like this...
Value1, Yes ; Value2, Yes ; Value3, No ... etc

On the AfterUpdate event of your combo...
IF cboYourComboName.Column(1) = "Yes" Then
Then YourDateField.Enabled = True
Else
YourMyDateField.Enabled = False
End if

**Use this same code behind the OnCurrent event of the form itself, so
that the enabling/disabling is always in synch with the combo selection.
----------------------------------------------------------------------
3. Since a change in the number of combo options might change in the
future, the best method is to store the Yes/No value with the combo values
in a seperate table, and use that little 2 column table as the RowSource for
your combo... rather than a ValueList.
Ex.
Value HasDate
ABC Yes
CDE Yes
FGH No etc... etc...
That way, if a sixth or seventh item is ever added, you just add that choice
to the table, with an approprite Yes or No, and nothing in your forms or
reports coding has to be re-edited to "evaluate" if that entry requires a
Date or not.
 
G

Guest

hi, thanks for the advice! i tried choice #2 - creating a combo box with two
columns, one with the value and the second with Yes or No. However, for some
reason this isn't working. I tried

cboCurrent_status_of_dog.Column(1) = "Yes" then
Date_of_death.Enabled = True
Else
Date_of_death.Enabled = False
End if

And i used the same code behind the Oncurrent event of the form itself.
For some reason the code doesn't like the "cbo" part.....and then i tried
Me.Current_status_of_dog, and that didn't produce an error, but it didn't
work either.

What is cbo and am I doing this right?

Thanks so much for your help, I greatly appreciate it!
 
G

Guest

I actually just got it to work using Me.current_status_of_dog instead of the
cbo prefix. thanks so much for the help!

ps - what does cbo mean?
 
A

Al Camp

Did you set the NOOfColumns property to 2, and set the ColumnWidth to
something like 1" ; .5", and the ListWidth to 1.5", and set the BoundColumn
to 1?
Can you see the two columns when you drop down the combo?

Have you used EventProcedures before? Sounds like your code is not entered
properly. Just to review...
1. Go to the AfterUpdate event of your combo, and place you cursor in the
text box associated with that event.
2. Using the little down arrow on the right, select Event Procedure
3. Click the button with 3 dots ( ... ) to the right.
4. Your EventProcedure code behind the combo AfterUpdate event should look
like this...
Private Sub cboCurrent_status_of_dog_AfterUpdate()
If cboCurrent_status_of_dog.Column(1) = "Yes" Then
Date_of_death.Enabled = True
Else
Date_of_death.Enabled = False
End if
End sub
5. Repeat this process with the AfterUpdate event of Form OnCurrent...
 
A

Al Camp

I missed this post before I re-replied... so disregard my post. Sounds
like your OK now. Good deal!
"cbo" is a naming convention in Access that identifies that control as a
combobox. lstMyList would indicate a ListBox.. etc..
It is not critical to use naming conventions... whatever you name the
control... that's what you need to refer to in your code

If you named your combo Current_Status_Of_Dog, then you need to use that
name.
 

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