6 Replies Latest reply: Jun 27, 2017 10:42 AM by Michael Castillo RSS

    Check if field is selected or not via macro

    Michael Castillo

      Hello!  I apologize if this is in the wrong place; scripting seemed the most appropriate. 

       

      I'm new to QlikView and am attempting to write a macro in v12.0.20400 where I need to check if a specific field has been selected or not.  Having a msgbox is not my desired result, but a way for me to figure out the syntax of the condition.  The field is Year and I have searched the community extensively, but nothing I've come across works.  I'll provide examples of what I've tried below, but for confidentiality purposes, I cannot upload the QVW.

       

      When the year is already selected, this below code returns the year. I suspect this is returning a string, but am not 100% sure.  When the year is not selected, i.e. does not display in Current Selections, the macro fails with "Invalid procedure call or argument".

      Set yearValue = ActiveDocument.Fields("Year").GetSelectedValues

      If yearValue(0).Text = ""  Then

      msgbox("No year selected!")

      Else

      msgbox(yearValue(0).Text)

      End If

       

      From https://community.qlik.com/thread/86290, I should be able to use the field directly.  I tried the following, but it too failed; this time with, "Wrong number of arguments or invalid property assignment: 'Year'".  I tried without [] and ""  instead and got the same result.

      If IsNull([Year]) = -1  Then

           msgbox("No year selected!")

      Else

           msgbox(yearValue(0).Text)

      End If

      From https://community.qlikview.com/thread/10952, I should be able to use the field directly.  I tried the below code, but it failed as well; "Type mismatch: 'GetSelectedCount'.  I've also tried without "", but received, "Wrong number of arguments or invalid property assignment: 'Year'".

      If GetSelectedCount("Year") > 1  Then

           msgbox("No year selected!")

      Else

           msgbox(yearValue(0).Text)

      End If

      From https://community.qlik.com/thread/164879, I tried the below and it too fails.  Specifying Year without quotes returns, "Wrong number of arguments or invalid property assignment: 'Year'".  Specifying Year with quotes returns, "Type mismatch: 'GetFieldSelections'".

      If IsNull(GetFieldSelections("Year")) > -1

           msgbox("No year selected!")

      Else

           msgbox(yearValue(0).Text)

      End If

      I've also tried IsEmpty with all of these with no luck.  Does anyone know what I'm missing here?