Nested If result based on combo box value

S

Santa-D

I've been trying to figure out (with no luck) a way to return a string
value to a text box based on a result from a combo box.

To try and keep it simple:

If Combobox = Value.A then textbox.value = Result.A
If Combobox = Value.B then textbox.value = Result.B
If Combobox = Value.C then textbox.value = Result C

I tried to do a select case but i obviously had the syntax wrong.

Any assistance is kindly appreciated.
 
G

Greg Maxey

I am assuming that these are UserForm objects:

Private Sub ComboBox1_Change()
Me.TextBox1 = Me.ComboBox1
End Sub
 
D

Doug Robbins - Word MVP

What type of combobox are we talking about?

For a Dropdown type FormField as used in a protected document, you would use

Dim str as String
With ActiveDocument
With .FormFields("Dropdown1").DropDown
str = .ListEntries(.Value).Name
End With
If str = A Then
.FormFields("Text1").Result = ResultA
ElseIf str = B Then
.FormFields("Text1").Result = ResultB
Else
.FormFields("Text1").Result = ResultC
End If
End With

For a combobox on a userform, simply

If Combobox1.Value = A Then
TextBox1.Text = ResultA
ElseIF Combobox1.Value = B Then
TextBox1.Text = ResultB
Else
TextBox1.Text = ResultC
End If


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
S

Santa-D

What type of combobox are we talking about?

For a Dropdown type FormField as used in a protected document, you would use

Dim str as String
With ActiveDocument
With .FormFields("Dropdown1").DropDown
str = .ListEntries(.Value).Name
End With
If str = A Then
.FormFields("Text1").Result = ResultA
ElseIf str = B Then
.FormFields("Text1").Result = ResultB
Else
.FormFields("Text1").Result = ResultC
End If
End With

For a combobox on a userform, simply

If Combobox1.Value = A Then
TextBox1.Text = ResultA
ElseIF Combobox1.Value = B Then
TextBox1.Text = ResultB
Else
TextBox1.Text = ResultC
End If

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP










- Show quoted text -

Thanks Doug,

It's a formfield on a protected document and I've seen where I wa
 
S

Santa-D

What type of combobox are we talking about?

For a Dropdown type FormField as used in a protected document, you would use

Dim str as String
With ActiveDocument
With .FormFields("Dropdown1").DropDown
str = .ListEntries(.Value).Name
End With
If str = A Then
.FormFields("Text1").Result = ResultA
ElseIf str = B Then
.FormFields("Text1").Result = ResultB
Else
.FormFields("Text1").Result = ResultC
End If
End With

For a combobox on a userform, simply

If Combobox1.Value = A Then
TextBox1.Text = ResultA
ElseIF Combobox1.Value = B Then
TextBox1.Text = ResultB
Else
TextBox1.Text = ResultC
End If

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP










- Show quoted text -

Thanks Doug,

It is a formfield in a protected document. I've seen where I went
wrong. Thanks again for your help.
 

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