A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Selection makes text box visible/hidden



 
 
Thread Tools Display Modes
  #1  
Old April 9th, 2009, 09:09 PM posted to microsoft.public.access.forms
TVComputer
external usenet poster
 
Posts: 5
Default Selection makes text box visible/hidden

I am using a combo box to allow the user multiple selections on a
list. Once choices are selected I want to show text boxes that
correlate only to those selection and make the rest hidden.

Here's what I have so far:

Private Sub ComboBoxA_LostFocus()
If ComboBoxA.Selected(ChoiceA) = True Then
TextBoxA.Visible = True
Else: TextBoxA.Visible = False
End If
If ComboBoxA.Selected(ChoiceB) = True Then
TextBoxB.Visible = True
Else: TextBoxB.Visible = False
End If
If ComboBoxA.Selected(ChoiceC) = True Then
TextBoxC.Visible = True
Else: TextBoxC.Visible = False
End If
End Sub

The problem I am having is everything is reliant on ChoiceA. If
ChoiceA is selected then all are visible, if ChoiceA is deselected,
all are hidden. What am I missing?
  #2  
Old April 9th, 2009, 11:28 PM posted to microsoft.public.access.forms
Jeanette Cunningham
external usenet poster
 
Posts: 2,190
Default Selection makes text box visible/hidden

Hi TVComputer,
move the code to the after update event instead of the lost focus event.
try code like this--

Private Sub ComboBoxA_AfterUpdate
Select Case Me.ComboBoxA
Case "ChoiceA"
Me.TextBoxA.Visible = True
Me.TextBoxB.Visible = False
Me.TextBoxc.Visible = False

Case "ChoiceB"
Me.TextBoxA.Visible = False
Me.TextBoxB.Visible = True
Me.TextBoxc.Visible = False

Case "ChoiceC"
Me.TextBoxA.Visible = False
Me.TextBoxB.Visible = False
Me.TextBoxc.Visible = True

Case Else
End Select
End Sub


Note: the above code has not been tested.
You may find that you need to set all 3 textboxes to visible = false on the
form's property dialog.



Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


"TVComputer" wrote in message
...
I am using a combo box to allow the user multiple selections on a
list. Once choices are selected I want to show text boxes that
correlate only to those selection and make the rest hidden.

Here's what I have so far:

Private Sub ComboBoxA_LostFocus()
If ComboBoxA.Selected(ChoiceA) = True Then
TextBoxA.Visible = True
Else: TextBoxA.Visible = False
End If
If ComboBoxA.Selected(ChoiceB) = True Then
TextBoxB.Visible = True
Else: TextBoxB.Visible = False
End If
If ComboBoxA.Selected(ChoiceC) = True Then
TextBoxC.Visible = True
Else: TextBoxC.Visible = False
End If
End Sub

The problem I am having is everything is reliant on ChoiceA. If
ChoiceA is selected then all are visible, if ChoiceA is deselected,
all are hidden. What am I missing?



  #3  
Old April 10th, 2009, 01:38 AM posted to microsoft.public.access.forms
TVComputer
external usenet poster
 
Posts: 5
Default Selection makes text box visible/hidden

Hi Jeanette, thank you for your response. I tried to move it to
_AfterUpdate as you suggested but I still have the problem of all of
them being reliant on TextBoxA. I am using if-then-else statement (as
I showed in my original post), if that makes a difference. I really
don't know much about Visual Basic, I'm kind of learning as I go. One
thing, however, I am using a multi-select combo box and I want all the
selected choices to be visible and the ones not selected to be
hidden. So, TextBoxA AND TextBoxB may be visible with TextBoxC not,
OR TextBoxA AND TextBoxC visible with TextBoxB not. I tried your
example incorporating what I have said, but I still have the same
problem.

Here's what I tried:
Private Sub ComboBoxA_AfterUpdate
Select Case Me.ComboBoxA
Case "ChoiceA"
Me.TextBoxA.Visible = True

Case "ChoiceB"
Me.TextBoxB.Visible = True

Case "ChoiceC"
Me.TextBoxc.Visible = True

Case Else
End Select
End Sub

It still changes everything based on whether ChoiceA is selected or
not regardless of the others.

I hope this isn't too confusing!
  #4  
Old April 10th, 2009, 02:00 AM posted to microsoft.public.access.forms
Jeanette Cunningham
external usenet poster
 
Posts: 2,190
Default Selection makes text box visible/hidden

I think you mean a multi select listbox and not a combo box.
I don't understand what you are trying to do. An example with description is
more likely to be understood by someone trying to answer your question than
the ABC description in your post.
Why is it important to show/hide certain text boxes depending on what is
selected in the list box?

Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


"TVComputer" wrote in message
...
Hi Jeanette, thank you for your response. I tried to move it to
_AfterUpdate as you suggested but I still have the problem of all of
them being reliant on TextBoxA. I am using if-then-else statement (as
I showed in my original post), if that makes a difference. I really
don't know much about Visual Basic, I'm kind of learning as I go. One
thing, however, I am using a multi-select combo box and I want all the
selected choices to be visible and the ones not selected to be
hidden. So, TextBoxA AND TextBoxB may be visible with TextBoxC not,
OR TextBoxA AND TextBoxC visible with TextBoxB not. I tried your
example incorporating what I have said, but I still have the same
problem.

Here's what I tried:
Private Sub ComboBoxA_AfterUpdate
Select Case Me.ComboBoxA
Case "ChoiceA"
Me.TextBoxA.Visible = True

Case "ChoiceB"
Me.TextBoxB.Visible = True

Case "ChoiceC"
Me.TextBoxc.Visible = True

Case Else
End Select
End Sub

It still changes everything based on whether ChoiceA is selected or
not regardless of the others.

I hope this isn't too confusing!



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 04:10 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.