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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Deselect value from list box using macro

I need to deselect a value from the list box if the sum of total parts in this example is greater than the threshold in this case 300.

Can someone please help me with the macro to do this.

thank you

Chaya

4 Replies
Not applicable
Author

First, I created a variable called vSumParts with a value of:

=Sum(Parts)


Then I used the following macro, which will deselect the first selected value when the Sum of Parts is greater than 300.

Sub DeselectPart
val = ActiveDocument.Variables("vSumParts").GetContent.String
set fld = ActiveDocument.Fields("Description")

if val > 300 then
set mySelections = fld.GetSelectedValues

fld.ToggleSelect mySelections.Item(0).text
end if
End Sub


You would put this in the OnSelect of the field. The problem is, if only one value is selected and you deselect it, the Sum of Parts will be more than what it was and you'd end up with some sort of infinite loop. How do you intend to handle that situation? You probably want some logic in there to make sure there are selected values in the field.

Not applicable
Author

Thank you for bringing up about infinit loop. Haven't given a thought about it yet. But, in my actual document that I am working with , the list box that contains 20 different values. If the sum is >300, i need to deselect only values "Part1, Part2 and Part3" if they are selected else leave the rest of the selection as is.

Can you suggest on how to approach this?

Thank you.

Not applicable
Author

Here is my approach to this. Its working on what I need to do.

sub ClearSelection
val =ActiveDocument.Variables("vRowCount").GetContent.String
Set SelectedField=ActiveDocument.Fields("DESCRIPTION")
if val > 400 then
Set MySelections = SelectedField.GetSelectedValues
SelectedField.ToggleSelect "Claim Number"
end if
End Sub

Thank you getting me started.

Chaya

Not applicable
Author

GetSelectedValues creates an array of selected values. Then use fld.ToggleSelect mySelections.Item(0).text to determine the actual selected value. If one of the values is already selected, ToggleSelect will unselect it. If one of the values is not selected, it will not come up in this array. Basically, if

...
mySelections.Item(0).text = 'Part1' or mySelections.Item(0).text = 'Part2' then
fld.ToggleSelect mySelections.Item(0).text
end if


Or something like that...