Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

show selected values (with macro?)

hello guys,

I have quite a simple question here.

(see attach file)

All I want to do in when selecting any data in the field "ver"----> the select

value will apper in the big red text box and will change with any new selection.

I tried to do that:

I created a variable named him show,and built that macro:

Sub show





set

show = ActiveDocument.fields("ver").GetSelectedValues

end

sub

well....It doesn't working guys... 😞

thanx



1 Solution

Accepted Solutions
Not applicable
Author

Without a macro, you can use: GetFieldSelections(ver)

That will get you a comma separated list of the items that are selected. Put that (start with an equals sign) in your text box.

It is possible with a macro, but this method is much easier.

The reason your macro doesn't work is because you are not setting your Show variable in your macro. You're creating an object named Show which is like an array of selected values. This is completely unrelated to your Show variable (other than sharing the same name). In order to populate your Show variable with the Selections in your Show Object, you would need to loop through each Item and contatenate each Selection with all of the previous Selections.

View solution in original post

5 Replies
Not applicable
Author

well for some reason I can't upload the file...

anyway the data is look like that:

num,ver

15 hhq
20 ssd
25 scd
30 fbi
35 cai
40 btg
45 bgu
50 coi
55 gol
60 sil

thanx again.........

Not applicable
Author

Without a macro, you can use: GetFieldSelections(ver)

That will get you a comma separated list of the items that are selected. Put that (start with an equals sign) in your text box.

It is possible with a macro, but this method is much easier.

The reason your macro doesn't work is because you are not setting your Show variable in your macro. You're creating an object named Show which is like an array of selected values. This is completely unrelated to your Show variable (other than sharing the same name). In order to populate your Show variable with the Selections in your Show Object, you would need to loop through each Item and contatenate each Selection with all of the previous Selections.

Not applicable
Author

thanx alot.

indeed a simple solution Smile

Can you post yours with the macro? I'm not sure I've understand it..

I've done this to ignore the comma :

=



if(isnull(GetFieldSelections(ver)),'',GetFieldSelections(ver))

Not applicable
Author

I put together a quick sample of what the macro would look like. Hopefully, this clears up what I was talking about in regards to the Show Object vs. the Show Variable. In my sample, I have renamed the Object to ObjShow and the Variable to vShow.

Here's the macro:

Sub ShowVer

set ObjShow = ActiveDocument.Fields("ver").GetSelectedValues
' This is the Object you were creating

set var = ActiveDocument.Variables("vShow")
' This would be a reference to your variable

var.SetContent "", true ' Clear Variable

for i = 0 to ObjShow.Count - 1
varHolder = varHolder & ObjShow.Item(i).text & ", "
next

' This removes the extra comma
if Len(varHolder) > 2 then
varHolder = Left(varHolder, Len(varHolder) - 2)
end if

' Set the variable to the concatenated list of selections
var.SetContent varHolder, true

End Sub

Not applicable
Author

I certainly learn something new here.

great,its working

thanx