Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Button that makes multiple selections in same field

I am trying to create a button that will make multiple selections I have it working but when I try to have it make multiple selections within one field it only selections one.

Any suggestions?

12 Replies
prieper
Master II
Master II

Hi,

have a look into the API-Guide (Field - Select):

rem ** select two non-consecutive field values in field **
set f = ActiveDocument.Fields("Class")
set fv = f.GetNoValues 'empty array
fv.Add
fv.Add
fv(0).Text = "Group"
fv(0).IsNumeric = false
fv(1).Text = "Field"
fv(1).IsNumeric = false
f.SelectValues fv

HTH

Peter

Not applicable
Author

sorry but I am very new to QV, can you be a little more specfic? I have gone out and downloaded the API manual and will begin reviewing it as well.

Regards

johnw
Champion III
Champion III

The simplest way to make multiple selections in the field is to just connect the values together. So let's say you have a list box like this:

Fruit
-----
Apple
Mango
Orange
Pumpkin
Watermellon

And when they click a button, you want to select Mango, Orange and Pumpkin. Well, why those three? In this case, it's because we want to select all of the orange fruit. Well, that suggests that we should have another field, "Color". So we add the Color field. Now when we click on "Orange", those three fruits will be "selected".

Frankly, I don't think I've ever used a button to make selections in any of my applications. I just make other fields.

That said, buttons are not particularly difficult.

If you don't have version 9, you'll need to write a macro (tools -> edit module) to do the work. Peter was giving you an example of the main code in such a macro, though I wouldn't personally code it that way, so let's go from scratch. First, you'll need some data, so create a new file, and add this to the bottom of the script:

LOAD * INLINE [
Fruit
Apple
Mango
Orange
Pumpkin
Watermellon
];

Run the script and add a list box for Fruit. Then do tools -> edit module to create a macro. Cut and paste the following code:

sub OrangeFruit
set fruit = activedocument.fields("Fruit") ' fruit now refers to field Fruit
fruit.select "Orange" ' clears all selections in Fruit and selects Orange
fruit.toggleselect "Mango" ' selects Mango
fruit.toggleselect "Pumpkin" ' selects Pumpkin
end sub

Click OK to get back to your document. Add a button. In the button properties, on the General tab, under function, select Macro. Go to the macro tab, and select OrangeFruit as your macro name. Click OK. Pressing the button should now select the orange fruit.

Now if you click on the button, it should select the orange fruit.

If you have version 9, let's try it the version 9 way. Add a button. Under the properties for the button, go to the actions tab and click add. Click on selection and select in field. Hit OK. type in Fruit for the field and Mango for the search string. Then add -> selection -> toggle select -> Fruit -> Orange. Then add -> selection -> toggle select -> Fruit -> Pumpkin. Click on OK. Pressing the button should now select the orange fruit.

For reference, here is a sample file with both buttons as well as a Color field.

Not applicable
Author

I am currently using the exact same thing, but I have the problem, that if I make selections like these, they won't be stored in a bookmark 😞

I have a field, which I manipulate using buttons: Syntax:



Sub Customer ()
set doc = ActiveDocument
doc.Fields("Customer").Select "Customer"

If I then create a document bookmark, the value of this field is NOT stored in this bookmark.

As a test I created an additional listbox for this field. I can see that the button will change the value of the field, but its value is only used in the bookmark, if I manually select the value in the list box.

Has anyone here experienced something similar?

Not applicable
Author

If you want the "easy" approach, try using activity-selections and choose "switch between selections". Type what field you wish to make the selection in, then what selection to make.Create another one of that action below to add another selection to the total.

BR

Jakob

Not applicable
Author

I have found there is a bug !

Setting the array doesnt work unless you set both the .Text and .Number properties of the Item. the code below is a partial extract of some code that defaults a listbox to the values from a spreadsheet. ie (Heres 50 products I want analysing)

[Code]

set doc = ActiveDocument
set myselections = doc.fields("TerritoryID").GetSelectedValues

set sf = doc.fields("%key").GetNoValues
for i = 0 to myselections.count -1
'msgbox (myselections.Item(i).text)
sf.Add
sf(i).Text = myselections.Item(i).text
sf(i).Number = myselections.Item(i).text
sf(i).isNumeric = true
'msgbox (sf(i).Text)







[\Code]



peter_turner
Partner - Specialist
Partner - Specialist

Hello,

I had a similar problem when i needed to store complex selections where the results can change after each reload.

I had to use the action 'Select in Field' which a search string like this:
=Tag like 'A*' or Tag like 'B*'

You can do complex Or And etc etc on multiple values within a field, and combine this with multiple other fields as needed.
More info's on my post http://community.qlik.com/forums/t/19806.aspx

Peter.

Not applicable
Author

Sorry to push this up again, but I was wondering if anyone came across the problem that a field which was manipulated using

ActiveDocument.Field("Name").Select "value"

will not be stored correctly in a bookmark under QV8.5.

It looks like the value of the Field is changed by this manipulation (a list box says so), but in the bookmark all values of the Field are selected 😞

Not applicable
Author

Hi all

I have dont something very similar.

I have a macro thart selects a customer from a selection list (1 at a time), I am now needing to get the email address for the selected customer in the macro.

Any suggestions wold be greatly appriciated.