Hide Textbox Based on Combo Value

dino_christou

New member
Local time
Today, 22:13
Joined
Oct 7, 2008
Messages
9
Hi can someone please help me out here.

I would like to hide or display 3 text boxes based on a value in 1 combo.

Lets say the values in the combo are 1;2;3
And I have three text boxes called a, b and c

If I select 1 in the combo box I would only like text box a to be diplayed.
If I select 2 in the combo box I would only like text box b to be displayed.
If I select 3 in the combo box I would only like text box c to be displayed.

Is this possible?
If so, how would I go about doing this?

Sorry if this is an easy on, I'm very new to access and just getting to grips with it.

Many thanks in advance.
Dino :o
 
Howzit

Probably best in the on current event of your form

Call the event in the After Update event of your combobox
Code:
select case me.yourcombo
case is = 1
textboxa.visible = true
textboxb.visible = false
textboxc.visible = false
case is = 2
textboxa.visible = false
textboxb.visible = true
textboxc.visible = false
case is = 3
textboxa.visible = false
textboxb.visible = false
textboxc.visible = true
case else
something else
end select
 
Hi Kiwiman,

Thanks for your help with this, need a little more with the code you gave me please.

I put an Event Procedure in the 'On Current' on the form and put the code:

Private Sub Form_Current()

Select Case Me.callcount
Case Is = 1
textboxa.Visible = True
textboxb.Visible = False
textboxc.Visible = False
Case Is = 2
textboxa.Visible = False
textboxb.Visible = True
textboxc.Visible = False
Case Is = 3
textboxa.Visible = False
textboxb.Visible = False
textboxc.Visible = True

End Select

End Sub

callcount being my combobox.
I create 3 text boxes labelled as in the cade just to try it out.

Put Event Procedure in "After Update" in the combobox.
Save eveything and nothing seems to be hiding on the selections of numbers in the combobox. I tried changing the form to Dataentry yes and no, with no only the 3rd text box stays visable. With data enrty on, all three are visable and nothing hides etc when selecting a number form the combobox.

What have I done wrong?

Many Thanks
Dino
 
Hi Kiwi,

I managed to get it working but did it slightly dif.

I didnt bother with a Form event, I just used combo event "On Change"
And entered this code (pretty much them same really)

Code:
Private Sub callcount_Change()

Select Case Me.callcount
Case Is = 1
textboxa.Visible = True
textboxb.Visible = False
textboxc.Visible = False
Case Is = 2
textboxa.Visible = False
textboxb.Visible = True
textboxc.Visible = False
Case Is = 3
textboxa.Visible = False
textboxb.Visible = False
textboxc.Visible = True

End Select
End Sub

Thanks for your help.

Regards
Dino
 
What would one do if they would like the same ouput for multiple selections in combo box? Here is waht I have, but it does not work. I am rather new at coding. Do I have to list the true/false for each selection?

Select Case Me.MARITAL_STATUS
Case Is = "MARRIED" Or "SEPARATED"
Me.SPOUSE_ADDRESS.Visible = True
Me.SPOUSE_CELL.Visible = True
Me.SPOUSE_CITY.Visible = True
Me.SPOUSE_E_MAIL.Visible = True
Me.SPOUSE_FNAME.Visible = True
Me.SPOUSE_HOME.Visible = True
Me.SPOUSE_LANG.Visible = True
Me.SPOUSE_LNAME.Visible = True
Me.SPOUSE_SAME.Visible = True
Me.SPOUSE_STATE.Visible = True
Me.SPOUSE_WORK.Visible = True
Me.SPOUSE_ZIP.Visible = True
Case Is = "SINGLE" Or "DIVORCED"
Me.SPOUSE_ADDRESS.Visible = False
Me.SPOUSE_CELL.Visible = False
Me.SPOUSE_CITY.Visible = False
Me.SPOUSE_E_MAIL.Visible = False
Me.SPOUSE_FNAME.Visible = False
Me.SPOUSE_HOME.Visible = False
Me.SPOUSE_LANG.Visible = False
Me.SPOUSE_LNAME.Visible = False
Me.SPOUSE_SAME.Visible = False
Me.SPOUSE_STATE.Visible = False
Me.SPOUSE_WORK.Visible = False
Me.SPOUSE_ZIP.Visible = False
End Select

Thank you in advance for the help.
 
Just change the Case lines to

Case "MARRIED", "SEPARATED"

and

Case "SINGLE","DIVORCED"
 
You, sir, are a genius. Thank you very much for the help. IT WORKS!!!
 
Now that I have that working correctly, I have another question. Is there a way to add "sub-categories" to this type of application? Explaination:

Now that I have these criteria defined and hidden when appropriate, I am adding more functionality. I also have a toggle button for “Spouse address same as employee” to account for spouses who are legally separated. This toggle is hidden for single or divorced employees. In the case of married employees, selecting the toggle hides spouse address, city, state, and zip text boxes. I currently have this set up as separate code to operate independently, but my concern is this:

Say a couple is separated, so I have a separate address for spouse. Then they decide to get back together, therefore negating the need for a separate address. If one of my clerks selects the toggle, currently it will simply hide the secondary address. If the offending clerk does not physically delete the info, I will wind up with errant info in my table. Given the size of my organization, this could become a problem far bigger than just additional storage space eaten up by unnecessary information.

My company also mandates a form be filled out in the case that both spouses work for my company. There is another toggle for that purpose. When selected, it opens a text box for inputting the date the form was signed. The same issue applies in the case of a couple employed by my organization that gets a divorce. The possibility of additional wayward info exists.

None of this info is needed for single or widowed employees. I hope this explains it well enough. If not, please let me know. Thank you again for your continued support.
 
HOLY CRAP!! UMMM, PROBLEM!!

I have the following in place:

Select Case Me.MARITAL_STATUS
Case Is = "SINGLE", "DIVORCED", "WIDOW", "WIDOWER"
Me.SPOUSE_ADDRESS.Visible = False
Me.SPOUSE_CELL.Visible = False
Me.SPOUSE_CITY.Visible = False
Me.SPOUSE_E_MAIL.Visible = False
Me.SPOUSE_FNAME.Visible = False
Me.SPOUSE_HOME.Visible = False
Me.SPOUSE_LANG.Visible = False
Me.SPOUSE_LNAME.Visible = False
Me.SPOUSE_SAME.Visible = False
Me.SPOUSE_STATE.Visible = False
Me.SPOUSE_WORK.Visible = False
Me.SPOUSE_ZIP.Visible = False
Me.SPOUSE_SAME = False
Me.DUAL_EMP = False
Me.NON_DISCL = False
Case Is = "MARRIED", "SEPARATED"
Me.SPOUSE_ADDRESS.Visible = True
Me.SPOUSE_CELL.Visible = True
Me.SPOUSE_CITY.Visible = True
Me.SPOUSE_E_MAIL.Visible = True
Me.SPOUSE_FNAME.Visible = True
Me.SPOUSE_HOME.Visible = True
Me.SPOUSE_LANG.Visible = True
Me.SPOUSE_LNAME.Visible = True
Me.SPOUSE_SAME.Visible = True
Me.SPOUSE_STATE.Visible = True
Me.SPOUSE_WORK.Visible = True
Me.SPOUSE_ZIP.Visible = True
Me.SPOUSE_SAME = True
Me.DUAL_EMP = True
Me.NON_DISCL = True
End Select


For some reason, this code is entering 12-31-1899 12:00 as the date for the non-disclosure form. Luckily, I stopped it in time before it caused MAJOR issues, but not sure why it happened. It did not happen before I added those two lines in the code. PLEASE HELP!!

NON_DISCL is type date (text box)
DUAL_EMP is type Yes/No (toggle button)
 
Well, you have this:

Me.NON_DISCL = False

Which is telling the date field that the value is 0 which equates to 12-31-1899 12:00.

So did you perhaps want this instead:

Me.NON_DISCL.Visible = False
 
Why, yes I did. I feel completely inept. Thank you for showing me the error of my ways. I suck!
 
Why, yes I did. I feel completely inept. Thank you for showing me the error of my ways. I suck!

Now, now - none of that :) We've all done that at one time or another (believe it). So, don't feel bad.
 
Ha ha!! That makes me feel better! I appreciate your help. I will try to better audit my code before posting my inabilities on the internet. Ha ha!!
 
Hi Kiwi,

I managed to get it working but did it slightly dif.

I didnt bother with a Form event, I just used combo event "On Change"
And entered this code (pretty much them same really)

Code:
Private Sub callcount_Change()

Select Case Me.callcount
Case Is = 1
textboxa.Visible = True
textboxb.Visible = False
textboxc.Visible = False
Case Is = 2
textboxa.Visible = False
textboxb.Visible = True
textboxc.Visible = False
Case Is = 3
textboxa.Visible = False
textboxb.Visible = False
textboxc.Visible = True

End Select
End Sub

Thanks for your help.

Regards
Dino

Hi dino_christou

I tried this but every time I change the combo box in a record, it becames the standard for all other records.
I want to show or hide text box if the choice is a Internal combustion engine or if it is an hybrid or electric.

"Private Sub EngineID_Change()

Select Case Me.EngineID
Case Is = 1
Text404.Visible = False
Text405.Visible = False
Text406.Visible = False
Text407.Visible = False
Text408.Visible = False
Label403.Visible = False
Frame402.Visible = False
Case Is = 2
Text404.Visible = False
Text405.Visible = False
Text406.Visible = False
Text407.Visible = False
Text408.Visible = False
Label403.Visible = False
Frame402.Visible = False
Case Is = 3
Text404.Visible = False
Text405.Visible = False
Text406.Visible = False
Text407.Visible = False
Text408.Visible = False
Label403.Visible = False
Frame402.Visible = False
Case Is = 4
Text404.Visible = True
Text405.Visible = True
Text406.Visible = True
Text407.Visible = True
Text408.Visible = True
Label403.Visible = True
Frame402.Visible = True
Case Is = 5
Text404.Visible = True
Text405.Visible = True
Text406.Visible = True
Text407.Visible = True
Text408.Visible = True
Label403.Visible = True
Frame402.Visible = True

End Select
End Sub"
 

Users who are viewing this thread

Back
Top Bottom