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 Merge in Button

Hi All,

I have two macros for two separate buttons. I want to merge these two buttons. I have looked at other posts which do similar stuff but cannot seem to get them to work. Basically one sheet is overlayed with another in a tab. I would like to be able to switch between each 'layer'.

my two macros are

Sub ShowTicket
set v = ActiveDocument.Variables("vShow")
v.SetContent "Ticket",true
End Sub


and

Sub ShowEffort
set v = ActiveDocument.Variables("vShow")
v.SetContent "Effort",true
End Sub


I would like to be able to toggle via either and also with the name changing on the button for each. My attempt ended up making all the charts disappear!

6 Replies
Not applicable
Author

Hi,

I think you should use only one variable

In the first chart, on the display condition put =vShow
In the second chart, on the display condition put =not vShow
Keep only one macro, in your macro you have to do something like vshow.value = not vshowvalue . (Sorry I don't remember the exact syntax bout I think you should use the ActiveDocument.Variables("vShow").GetContent method to get the actual value).

Then to manage the button name. You can use an if statement like if vShow then 'Effort' else 'Ticket' end if (This is the idea not the right syntax :)). You can use it directly in the button expressions or in Macro if you prefer.

Hope it helps,

sorry if I misunderstood your demand 🙂 .

Regards

Not applicable
Author

Here is a chunk of code I use to swop the value of a variable and the button text:

CurrVal = ActiveDocument.Variables("vAccum").GetContent.String
NewVal=CurrVal
set button1 = ActiveDocument.getsheetobject("BU02")
set propB = button1.GetProperties

Select Case CurrVal ' 0=no acc 1=full acc
Case "0"
NewVal = "1"
propB.Text.v = "No accum"
Case Else ' 1 expected but fail safe if unknown
NewVal = "0"
propB.Text.v = "Full accum"
End Select

However, I would now use two buttons that were enabled/disabled depending on the variable value. Why? well the manuals consistently say that in server you should not change an objects attributes - it does work and everyone does it but as there is an alternative I prefer to use it just in case!

Regards,

Gordon

ActiveDocument.Variables("vAccum").SetContent NewVal, true

button1.SetProperties propB

Not applicable
Author

that should read:

CurrVal = ActiveDocument.Variables("vAccum").GetContent.String
NewVal=CurrVal
set button1 = ActiveDocument.getsheetobject("BU02")
set propB = button1.GetProperties

Select Case CurrVal ' 0=no acc 1=full acc
Case "0"
NewVal = "1"
propB.Text.v = "No accum"
Case Else ' 1 expected but fail safe if unknown
NewVal = "0"
propB.Text.v = "Full accum"
End Select

ActiveDocument.Variables("vAccum").SetContent NewVal, true

button1.SetProperties propB

Not applicable
Author

My vShow variable is currently 'Effort'. Should this be changed?

Not applicable
Author

Thanks for the info Gordon. i'll test both and see which is most suitable for my sheet.

Not applicable
Author

To adapt the Gordon's exemple to your case, I think you just have to replace 'No Accumulation' / 'Full Accumulation' by 'Efforts' and 'Tickets'

to workaround the button change properties, I would suggest a little change in the code above : replace the propB object by a variable which contains the button name (let's call it vButtonName). Then in the QlikView button interface, set the General / Text Value expression to =vButtonName. So you shouldn't need to use two buttons.

Hope it helps

Regards