Help!

Combobox populate textbox alt. label

 
  

Post new topic   General Reply to Topic (not reply to a specific post)    Forums Home -> User Forms RSS
Next:  Problem with Preferred Column widths in Word 2003  
Author Message
littleme
External


Since: Mar 29, 2006
Posts: 3



PostPosted: Mon Feb 19, 2007 7:19 am    Post subject: Combobox populate textbox alt. label
Archived from groups: microsoft>public>word>vba>userforms (more info?)

Hello again.

Thank you for the excellent help last time I posted here.

Have a new small problem. Have searched the forum but cant seem to
find what I need. Im very new to allt his so...

What I would like is: depending on what value is selected form
combobox1, textbox (or label is possible) is populated with 1 of 3
values.

All help is welcome and appreciated...
Back to top
Jean-Guy Marcil
External


Since: Nov 30, 2006
Posts: 68



PostPosted: Mon Feb 19, 2007 10:42 am    Post subject: Re: Combobox populate textbox alt. label [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

littleme was telling us:
littleme nous racontait que :

> Hello again.
>
> Thank you for the excellent help last time I posted here.
>
> Have a new small problem. Have searched the forum but cant seem to
> find what I need. Im very new to allt his so...
>
> What I would like is: depending on what value is selected form
> combobox1, textbox (or label is possible) is populated with 1 of 3
> values.

You did not look very hard... This is one of the most common questions...
Wink

Here is one way of doing it (Based on a simple userform with only two
controls on it):

'_______________________________________
Private Sub ComboBox1_Change()

With Me.ComboBox1
Select Case .ListIndex
Case 0
Me.TextBox1.Text = "Nothing was was selected"
Case 1
Me.TextBox1.Text = """Choice 1"" was selected"
Case 2
Me.TextBox1.Text = """Choice 2"" was selected"
Case 3
Me.TextBox1.Text = """Choice 3"" was selected"
End Select
End With

End Sub
'_______________________________________

'_______________________________________
Private Sub UserForm_Initialize()

With Me.ComboBox1
.AddItem "Select"
.AddItem "Choice 1"
.AddItem "Choice 2"
.AddItem "Choice 3"
.ListIndex = 0
End With

End Sub
'_______________________________________

Of course, if you have more than a few items in the dropdown, you would use
an array and the .List() method to populate it.

--

Salut!
Jean-Guy Marcil - Word MVP
jmarcilREMOVE RemoveThis @CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org
Back to top
littleme
External


Since: Mar 29, 2006
Posts: 3



PostPosted: Tue Feb 20, 2007 1:42 am    Post subject: Re: Combobox populate textbox alt. label [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On 19 Feb, 16:42, "Jean-Guy Marcil" <DontEvenTry@NoSpam> wrote:
> littleme was telling us:
> littleme nous racontait que :
>
> > Hello again.
>
> > Thank you for the excellent help last time I posted here.
>
> > Have a new small problem. Have searched the forum but cant seem to
> > find what I need. Im very new to allt his so...
>
> > What I would like is: depending on what value is selected form
> > combobox1, textbox (or label is possible) is populated with 1 of 3
> > values.
>
> You did not look very hard... This is one of the most common questions...
> Wink
>
> Here is one way of doing it (Based on a simple userform with only two
> controls on it):
>
> '_______________________________________
> Private Sub ComboBox1_Change()
>
> With Me.ComboBox1
> Select Case .ListIndex
> Case 0
> Me.TextBox1.Text = "Nothing was was selected"
> Case 1
> Me.TextBox1.Text = """Choice 1"" was selected"
> Case 2
> Me.TextBox1.Text = """Choice 2"" was selected"
> Case 3
> Me.TextBox1.Text = """Choice 3"" was selected"
> End Select
> End With
>
> End Sub
> '_______________________________________
>
> '_______________________________________
> Private Sub UserForm_Initialize()
>
> With Me.ComboBox1
> .AddItem "Select"
> .AddItem "Choice 1"
> .AddItem "Choice 2"
> .AddItem "Choice 3"
> .ListIndex = 0
> End With
>
> End Sub
> '_______________________________________
>
> Of course, if you have more than a few items in the dropdown, you would use
> an array and the .List() method to populate it.
>
> --
>
> Salut!
> Jean-Guy Marcil - Word MVP
> jmarcilREM... RemoveThis @CAPSsympatico.caTHISTOO
> Word MVP site:http://www.word.mvps.org

Thank you. Got it working just fine. One more question though:

The user can type their own title in the combobox which is fine.
However, if they type something that IS NOT in the array, I would like
the text box to say XXX. How would I do that?
Back to top
Jean-Guy Marcil
External


Since: Nov 30, 2006
Posts: 68



PostPosted: Tue Feb 20, 2007 8:21 am    Post subject: Re: Combobox populate textbox alt. label [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

littleme was telling us:
littleme nous racontait que :

> On 19 Feb, 16:42, "Jean-Guy Marcil" <DontEvenTry@NoSpam> wrote:
>> littleme was telling us:
>> littleme nous racontait que :

<snip>

> Thank you. Got it working just fine. One more question though:
>
> The user can type their own title in the combobox which is fine.
> However, if they type something that IS NOT in the array, I would like
> the text box to say XXX. How would I do that?

'_______________________________________
Private Sub ComboBox1_Change()

With Me.ComboBox1
Select Case .ListIndex
Case 0
Me.TextBox1.Text = "Nothing was was selected"
Case 1
Me.TextBox1.Text = """Choice 1"" was selected"
Case 2
Me.TextBox1.Text = """Choice 2"" was selected"
Case 3
Me.TextBox1.Text = """Choice 3"" was selected"
Case Else
Me.TextBox1.Text = "XXX"
End Select
End With

End Sub
'_______________________________________


--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE DeleteThis @CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org
Back to top
Display posts from previous:   
Post new topic   General Reply to Topic (not reply to a specific post)    Forums Home -> User Forms All times are: Eastern Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum