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: 
canoebi99
Partner - Creator
Partner - Creator

How do I set multiple values in list box from 4 variables via macro

Hi All,

I have four variables that are set on load of the document called:

vPrevWeekEndingDate

vPrevWeekEndingDate2

vPrevWeekEndingDate3

vPrevWeekEndingDate4

These basically hold the last four week ending dates.

Within a macro I then need to apply these dates to the selection list I have for WeekEnding Dates.

When setting a single value I have used the below code which has worked perfectly:

ActiveDocument.Fields("WeekEnding").Select getVariable("vPrevWeekEndingDate")

However I am not sure of the syntax to set all four values into the list. I have tried the following but it doesn't work:

ActiveDocument.Fields("WeekEnding").Select("( getVariable(vPrevWeekEndingDate)|getVariable(vPrevWeekEndingDate)|getVariable(vPrevWeekEndingDate)|getVariable(vPrevWeekEndingDate))")

I am sure it is something to do with the quotes because I had to take the quotes out from around each variable otherwise I get an error on checking but without the quotes I don't get anything selected?

Can anyone help with the required syntax to do this please?

Many thanks

Ben

1 Solution

Accepted Solutions
MayilVahanan

Hi

Try like this

sub CurrentSelection

          set f=ActiveDocument.GetField("[WeekEnding]")

          set v1 = ActiveDocument.Variables("vPrevWeekEndingDate2")

          set v2 =ActiveDocument.Variables("vPrevWeekEndingDat3")

          set v3 =ActiveDocument.Variables("vPrevWeekEndingDate4")

           set v4 =ActiveDocument.Variables("vPrevWeekEndingDate")

             v5 = "(" & v1.GetContent.String & "|" & v2.GetContent.String & "|" & v3.GetContent.String &"|" & v4.GetContent.String &")"

           msgbox v5

          f.select v5

end sub

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.

View solution in original post

4 Replies
MayilVahanan

HI

Why you refer macro rather than trigger selection?

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.
MayilVahanan

Hi

Try like this

sub CurrentSelection

          set f=ActiveDocument.GetField("[WeekEnding]")

          set v1 = ActiveDocument.Variables("vPrevWeekEndingDate2")

          set v2 =ActiveDocument.Variables("vPrevWeekEndingDat3")

          set v3 =ActiveDocument.Variables("vPrevWeekEndingDate4")

           set v4 =ActiveDocument.Variables("vPrevWeekEndingDate")

             v5 = "(" & v1.GetContent.String & "|" & v2.GetContent.String & "|" & v3.GetContent.String &"|" & v4.GetContent.String &")"

           msgbox v5

          f.select v5

end sub

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.
canoebi99
Partner - Creator
Partner - Creator
Author

Hi Mayil,

Thanks for the reply, I need to use a macro to set the values as it is all part of a macro that runs a report and e-mails the report out.

I tried your code but it still fails where it is setting v5

Thanks

Ben

canoebi99
Partner - Creator
Partner - Creator
Author

Hi Again Mayil,

Sorry I jumped the gun and have just realised there was a typo in your code (vPrevWeekEndingDat3 was missing the e!) so now I have corrected that it is working great.

Thanks so much for your time and assistance with this one.

Regards

Ben