Skip to main content
Announcements
Qlik Connect 2025: 3 days of full immersion in data, analytics, and AI. May 13-15 | Orlando, FL: Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
jaymerry
Creator
Creator

Macro to test selected field value

Hello,

I try in a macro to test the selected value of a field ; however,I don't find the right syntax.

The following example ends with an error :

Sub OneValue

    

    Set ValsforField = ActiveDocument.Fields("Answ").GetSelectedValues

    If ValsforField.value = "No" then

        ActiveDocument.Fields("Answ").Select"Yes"

    elseif ValsforField.value = "Yes" then

        ActiveDocument.Fields("Answ").Select"No"

    end if

   

end sub

Thank you for you help,

Best Regards,

Jaymerry

1 Solution

Accepted Solutions
marcus_sommer

Hi Jaymerry,

.value is unknown and fit not correct then GetSelectedValues returns an array() - use instead .Item(0).Text

If ValsforField.Item(0).Text = "No" then
        ActiveDocument.Fields("Answ").Select"Yes"
    elseif ValsforField.
Item(0).Text = "Yes" then
        ActiveDocument.Fields("Answ").Select"No"
    end if

- Marcus

View solution in original post

2 Replies
marcus_sommer

Hi Jaymerry,

.value is unknown and fit not correct then GetSelectedValues returns an array() - use instead .Item(0).Text

If ValsforField.Item(0).Text = "No" then
        ActiveDocument.Fields("Answ").Select"Yes"
    elseif ValsforField.
Item(0).Text = "Yes" then
        ActiveDocument.Fields("Answ").Select"No"
    end if

- Marcus

jaymerry
Creator
Creator
Author

Thanks for your help, it works.

BR

Jaymerry