Mark
Mark

Reputation: 27

MS Word VBA for formfields

I am trying to assign a numeric value in VBA for a dropdown formfield. I have the Msgbox just to test functionality:

Sub ScreenB()
    Dim a As Double
    If ActiveDocument.FormFields("Dropdown9").DropDown.Value = No Then
        a = 1
    Else
        a = 2
    End If
    MsgBox a       
End Sub

With this code, my Msgbox does not change (it reads "2"), even when I change the the dropdown from Yes to No, or vice-versa. I also tried putting quotes around yes ("Yes") in the VBA code and got a Type Mismatch error.

Upvotes: 0

Views: 298

Answers (1)

basher
basher

Reputation: 2401

You should use FormFields.Result

Sub ScreenB()
    Dim a As Double
    If ActiveDocument.FormFields("Dropdown9").Result = "No" Then
        a = 1
    Else
        a = 2
    End If
    MsgBox a       
End Sub

Upvotes: 1

Related Questions