ltjumper
03-15-2014, 04:14 PM
I am trying to create a report for my Uncle (not computer savy) so that he can change a drop down box and based on the result of the drop down box it will change either the highlight color, or text color of a text box which he will then fill in. I have been running a test with the below script and it won't change the color of the text box and I'm not sure what I'm doing wrong. I would like it to be robust enough that if he were to change the drop down to "A" it would automatically change the associated text box to a different color and he wouldn't have to select that text box as the next form field. I also eventually would like to have this be a macro that all of my drop down boxes can use so I need help bringing in the drop down box bookmark name. Any help that you can provide would be great. thank you ahead.
Sub OnExitDDList()
Dim oFFs As FormFields
Dim unlink As String
Dim link As String
Dim ColorChange As String
Dim dropdownname As String
Dim a As Integer
Dim textname As String
'Dim r As Range
'Set r = Selection.Range
a = 0
ColorChange = "ColorChange"
link = "link"
unlink = "unlink"
Set oFFs = ActiveDocument.FormFields
Select Case oFFs("TestDropDown").Result
Case "A"
'oFFs("TestTextBox").Select
oFFs("TestTextBox").Result = "First letter of alphabet"
'Me.ActiveControl.BackColor = vbYellow
Selection.GoTo What:=wdGoToBookmark, Name:="TestTextBox"
Application.Run unlink
Selection.Font.Color = wdColorAqua
'r.HighlightColorIndex = wdYellow
a = 1
Case "B"
oFFs("TestTextBox").Result = "Second letter of alphabet"
a = 0
Case "C"
oFFs("TestTextBox").Result = "Third letter of alphabet"
a = 0
End Select
lbl_Exit:
If a = 1 Then
Application.Run link
a = 0
End If
Exit Sub
End Sub
Sub OnExitDDList()
Dim oFFs As FormFields
Dim unlink As String
Dim link As String
Dim ColorChange As String
Dim dropdownname As String
Dim a As Integer
Dim textname As String
'Dim r As Range
'Set r = Selection.Range
a = 0
ColorChange = "ColorChange"
link = "link"
unlink = "unlink"
Set oFFs = ActiveDocument.FormFields
Select Case oFFs("TestDropDown").Result
Case "A"
'oFFs("TestTextBox").Select
oFFs("TestTextBox").Result = "First letter of alphabet"
'Me.ActiveControl.BackColor = vbYellow
Selection.GoTo What:=wdGoToBookmark, Name:="TestTextBox"
Application.Run unlink
Selection.Font.Color = wdColorAqua
'r.HighlightColorIndex = wdYellow
a = 1
Case "B"
oFFs("TestTextBox").Result = "Second letter of alphabet"
a = 0
Case "C"
oFFs("TestTextBox").Result = "Third letter of alphabet"
a = 0
End Select
lbl_Exit:
If a = 1 Then
Application.Run link
a = 0
End If
Exit Sub
End Sub