Log in

View Full Version : Change Text Box Font based on Combo Box



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

ltjumper
03-15-2014, 04:31 PM
I had the answer all the time and just didn't realize it. All I had to do was put the below line of code in the case statement and it changes the text box text color to whatever I want it to be. I am still wanting to bring in the name of the drop down list and text boxes into VBA so if anyone has the answer to that I would greatly appreciate it. I Am going to use those to make this code universal rather than creating a different one of these for each drop down box (Hundreds)

oFFs("TestTextBox").Range.Font.Color =wdColorBlack

snb
03-16-2014, 04:33 AM
It would be nice if you:

- used code tags around VBA code in your post.
- posted a sample document to facilitate any helper.