Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to read values from an input field and add them to the current selection?

Hi all,

I have this problem:

I have a database with many fields,one of them is CUSTOMER  ( around 1000 rows).

I have a Excel file with 100 customers , I copy and paste all this customers in an input field.

And the question is :   How i can add this customers (from the input field) to the current selection?

Thanks

1 Solution

Accepted Solutions
masha-ecraft
Partner - Creator
Partner - Creator

Hi,

Here is a macro I used for such task:

sub CustomerListOnChange

set doc = ActiveDocument
set obj = doc.Fields("CUSTOMER")
set input = ActiveDocument.Variables("CustomerList")

varArray = input.GetContent.String

'replace line breaks with commas
if trim(varArray) <> "" then

varArray = Replace(varArray,chr(10),",")
varArray = Replace(varArray,chr(13),",")

varValue = split(varArray,",")

'Get a list of values already included in the current selection

set varSelection = obj.GetSelectedValues
j = varSelection.Count

'Add values to the list of selected values
for i=lbound(varValue) to ubound(varValue)
if varValue(i) <> "" then
varSelection.Add
varSelection(j).Text = varValue(i)
varSelection(j).IsNumeric = False
j = j+1
end if
next

'Make a new selection with the extended value list
obj.SelectValues varSelection, false, true

end if

end sub


The macro should be attached to the CustomerList variable OnChange event. CustomerList variable should be linked to the input field in your application.


/Masha

View solution in original post

4 Replies
Not applicable
Author

I think i need a Macro but which one?

masha-ecraft
Partner - Creator
Partner - Creator

Hi,

Here is a macro I used for such task:

sub CustomerListOnChange

set doc = ActiveDocument
set obj = doc.Fields("CUSTOMER")
set input = ActiveDocument.Variables("CustomerList")

varArray = input.GetContent.String

'replace line breaks with commas
if trim(varArray) <> "" then

varArray = Replace(varArray,chr(10),",")
varArray = Replace(varArray,chr(13),",")

varValue = split(varArray,",")

'Get a list of values already included in the current selection

set varSelection = obj.GetSelectedValues
j = varSelection.Count

'Add values to the list of selected values
for i=lbound(varValue) to ubound(varValue)
if varValue(i) <> "" then
varSelection.Add
varSelection(j).Text = varValue(i)
varSelection(j).IsNumeric = False
j = j+1
end if
next

'Make a new selection with the extended value list
obj.SelectValues varSelection, false, true

end if

end sub


The macro should be attached to the CustomerList variable OnChange event. CustomerList variable should be linked to the input field in your application.


/Masha

Not applicable
Author

Thx Masha

Not applicable
Author

Could someone attach a qvw with this example working?

DA