Insert String Based on Combo Box Result

J

Jeff Schneider

Newbie alert!

I've got 2 form fields: Dropdown1 & Text1. I want to populate Text1 based on
what the user selects in the Dropdown1 field. The text is loaded in 8
strings, myText1, myText2... myText8.

So if the user selects "1" from the dropdown, Text1 is populated by the
value of the myText1 string, if the user selects "2", populate Text1 with the
value of myText2 string, etc.

I'm trying to avoid using 8 different If...Then statementrs by using a
For...Next loop. The problem I'm having is identifying each string. How can I
use the For...Next counter to use the corresponding string? (i.e. If I use
"For i = 1 to 8", when i=3 how do use myText3)

Here's my macro:

Public Sub Text1Update()

Dim myText1, myText2, myText3, myText4, myText5, myText6, myText7, myText8
As String

myText1 = "Your request did not include a signed and dated form."
myText2 = "Your request did not include the date."
myText3 = "The additional information requested has not been received,
therefore we must close our files. If submitted we will reconsider the
request."
myText4 = "Reads the same as E3 there is obviously a problem…"
myText5 = "The request did not include an ID number, please include this on
form."
myText6 = "The receipt(s) submitted were less than the amount requested on
your form."
myText7 = "An itemized bill from your service provider showing the name and
address, customer name, itemized charges, type of service, service code and
date of service."
myText8 = "Incomplete statement received. Please resend."

For i = 1 To 8
If ActiveDocument.FormFields("Dropdown1").Result = i Then
ActiveDocument.FormFields("Text1").Result = myText & i 'My problem is
here
End If
Next i

End Sub
 
D

Dave Lett

Hi Jeff,

I created a new userform. I inserted one textbox (Text1) and one Combobox
(cmb1). I use a userform_activate event to populate the items in cmb1. Then,
I use a cmb1_Change() event to set the value of Text1. Here's the example:

Private Sub UserForm_Activate()
UserForm1.cmb1.AddItem "Item 1"
UserForm1.cmb1.AddItem "Item 2"
UserForm1.cmb1.AddItem "Item 3"
UserForm1.cmb1.AddItem "Item 4"
End Sub

Private Sub cmb1_Change()
Text1.Value = cmb1.Value
End Sub


HTH,
Dave
 
J

Jeff Schneider

I'll stress this again: I'm new at this...

If I did what you said correctly, I cannot select the ComboBox because the
form I am using is locked to keep the existing text protected. For the sake
of testing, I unlocked it and it worked, and leads me to problem 2...

I was using Form Fields so the user could tab between each field on the
form. I didn't see any tab options in the ComboBox properties.
 
D

Dave Lett

Hi Jeff,

I thought you were using a UserForm. However, you can apply the same
prinicples to a Formfields. In my document, I created one Dropdown formfield
(named "Dropdown1") and one Text formfield (named "Text1"). I created a
macro called "Test." I right-click the Dropdown1 formfield and click
properties. I add all of the possible items to the Items in drop-down list.
For the exit macro, I choose to have this Dropdown1 formfield run the "Test"
macro.

The "Test" macro looks like this:

Public Sub Test()
ActiveDocument.FormFields("Text1").Result =
ActiveDocument.FormFields("Dropdown1").Result
End Sub

HTH,
Dave
 

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