Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Macro to select values in listbox

Hello,

i'm trying to select the values in a list box but i only get this message:

    

     Type mismatch: 'ActiveDocument.Fields(...).Select'

My small macro only contains this code:

     ActiveDocument.Fields("UNIT").Select ActiveDocument.Fields("UNIT").GetSelectedValues

Can someone help me, please?

Kind regards

Piskitta

1 Solution

Accepted Solutions
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

I'm confused as to what you are trying to do. You are trying to make selections in the field "UNIT" that the user has already made selections in?

Re your type mismatch error. GetSelectedValues returns an IArrayOfFieldValue object. The function that reads IArrayOfFieldValue is SelectValues, not Select.

Set x = ActiveDocument.Fields("y").GetSelectedValues

ActiveDocument.Fields("z").SelectValues x

-Rob

View solution in original post

10 Replies
Not applicable
Author

Hi,

Use this code in ur macro..........

ActiveDocument.Fields("UNIT").Select "UNIT_VALUE"

Thanks & Regards,

Parag

Not applicable
Author

Thanks for your answer Parag, but it's not what I was looking for.

My macro needs to select the value choosed by the user. But no matter what I try i keep getting the same error.

This is my last test, with no sucess sadly...

Sub SelectUnit

          set UnitSelected = ActiveDocument.Fields("UNIT").GetSelectedValues

 

          for i = 0 to UnitSelected.Count - 1

                    ActiveDocument.Fields("UNIT").Select(UnitSelected(i))

          NEXT

End Sub

Best regards

Dulce

jduenyas
Specialist
Specialist

Try this:

   set UnitSelected=ActiveDocument.Fields("UNIT").GetselectedValues

   for i = 0 to val.Count-1
     ActiveDocument.Fields("UNIT").Select UnitSelected.Item(i).Text
   Next i

best regards

Not applicable
Author

Hello,

thanks for the answer but mu problem keeps being the same.

I tried everything that i could find in the internet. But I had no luck.

Thanks,once again.

Kind regards

Dulce

jduenyas
Specialist
Specialist

I am puzzled by what it is that you are trying to achieve and why it did not work for you.

This works:

ArrayListOfNames = Array("Name","Name",Name"...)

SelectInListBox "<ListBoxName>", ArrayListOfNames

....

Example:

List box name = MyListBox

ArrayListOfNames = Array("piskitta","jduenyas")

SelectInLisBox "MyListBox", ArrayOfNames

(Replace "Name" with your variables, replace <ListBoxName> with your list box name)

The names must already exit in the listbox in order to be "selected"

Alternately you can iterate through the array with a For...Next

Best regards

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

I'm confused as to what you are trying to do. You are trying to make selections in the field "UNIT" that the user has already made selections in?

Re your type mismatch error. GetSelectedValues returns an IArrayOfFieldValue object. The function that reads IArrayOfFieldValue is SelectValues, not Select.

Set x = ActiveDocument.Fields("y").GetSelectedValues

ActiveDocument.Fields("z").SelectValues x

-Rob

Not applicable
Author

Thanks Rob,

I didn't know what was going wrong here.

That fixed my problem.

Regards

Dulce

Not applicable
Author

Hi Rob,

how can i add another value to object returned by the function getSelectedValues?

Thanks

Not applicable
Author

Using SelectValues instead of select did not work for me.