Skip to main content
Announcements
Introducing a new Enhanced File Management feature in Qlik Cloud! GET THE DETAILS!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Macro to select fields from getfieldselections

Hi,

I need a macro to select all fields with the same name in 2 ListBox.

For example, if I select 16/11/2008 and 17/11/2008 in the date1 listbox, the macro have to auto-select the same fields for date2.

I tested 2 solutions :


sub Select_dates

ActiveDocument.getField("date2").ToggleSelect "getfieldselections(date1)"

end sub


sub Select_dates2

set fselected = ActiveDocument.Fields("date1").GetSelectedValues
ActiveDocument.Fields("date2").ToggleSelect fselected

end sub


Thanks in advance

1 Solution

Accepted Solutions
Not applicable
Author

This should work for you:

sub NewSelect
list = ActiveDocument.Variables("vDate1").GetContent.String
test = Split(list, ", ")

set fld = ActiveDocument.Fields("date2")

fld.Select test(0)

for i = 1 to UBOUND(test)
fld.ToggleSelect test(i)
next
End Sub


That takes the GetFieldSelections values for date1 using a variable. It then uses the VB command split, to separate that into array elements. For the first item, we use the normal select, which should select only that one. Then we use ToggleSelect for the rest to get the current selection and this one.

View solution in original post

4 Replies
Not applicable
Author

I found a solution but it work only for 1 slection, no mutliple selections.


sub Select_dates

ActiveDocument.Fields("date2").Select ActiveDocument.Evaluate("getfieldselections(date1)")

end sub


Not applicable
Author

This should work for you:

sub NewSelect
list = ActiveDocument.Variables("vDate1").GetContent.String
test = Split(list, ", ")

set fld = ActiveDocument.Fields("date2")

fld.Select test(0)

for i = 1 to UBOUND(test)
fld.ToggleSelect test(i)
next
End Sub


That takes the GetFieldSelections values for date1 using a variable. It then uses the VB command split, to separate that into array elements. For the first item, we use the normal select, which should select only that one. Then we use ToggleSelect for the rest to get the current selection and this one.

Not applicable
Author

Thanks for your answer.

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

You were on the right track with the example you uploaded. It's a one-liner.

ActiveDocument.Fields("date2").SelectValues ActiveDocument.Fields("date1").GetSelectedValues

With V9, I think you can do it without a macro but I'm not sure of the Action specifics. Anyone?

-Rob