Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

For loop in macro not working when select field

Hi

See enclosed code. As you can see I retrieve all excluded values(getselected is not used, since it has a ' in front).

I get 4078 records. In the loop for debugging purpose i only loop 10 times.

When I get the current Item in the loop and display the text in the msgbox I can see that I get the correct value.

But when I try to select this value in the field nothing happens.

In the 2 last lines I did test selecting * which works and I hardcoded "2Big" which also works. I have searched the forum and seen that:

ActiveDocument.GetField("CONCERN_NAME").Select trim(vCompanies.Item(i).Text)  should work. The trim is just added to secure no extra spaces is there. Removing the trim won't change the result.

I'm using Qlikview 10 SR1 64 bit.

Can anyone please suggest why it's not working.

sub AutoExport

dim vCustomers

dim activeSheet

dim vCompanies

dim vCompanyName

set activeSheet = ActiveDocument.ActiveSheet

set vCustomers = ActiveDocument.GetField("CONCERN_NAME")

'set vCompanies = vCustomers.GetSelectedValues

set vCompanies = vCustomers.GetExcludedValues(10000)

  for i = 0 to 10'vCompanies.Count-1

      set vCompanyName=vCompanies.Item(i)

    qvlib.MsgBox(vCompanyName.Text)

     ActiveDocument.GetField("CONCERN_NAME").Select trim(vCompanies.Item(i).Text)

     'ActiveDocument.GetField("CONCERN_NAME").Select "*"   '//This works, but select all!!!!!!!

     'ActiveDocument.GetField("CONCERN_NAME").Select "2Big" '//This works also, but hardcoding every possible records is not possible!!!!!!!

     call Nextmethod()

next

1 Solution

Accepted Solutions
Not applicable
Author

Hi

I did find the solution, a rather obvious one actually. But sometimes you are blind when looking at your own code.

Since I in the first one selects Excluded values, I only get values that are excluded.And since they are excluded I can't select them. If I cleared other selections after the getExludedValues it would be possible to select them.

I my case I didn't want to clear the other selections.

Working code:

vCustomers.SelectPossible

set vCompanies = vCustomers.GetSelectedValues(10000)

for i = 0 to vCompanies.Count-1

      set vCompanyName=vCompanies.Item(i)

     ActiveDocument.Fields("CONCERN_NAME").Select vCompanies.Item(i).Text

     vCurrency=ActiveDocument.GetField("CurrencyCode_Reporting").GetPossibleValues.Item(0).Text

     ActiveDocument.Fields("CurrencyCode").Select vCurrency

     call someMethod()

  next

View solution in original post

4 Replies
Not applicable
Author

Hi,

try   ActiveDocument.Fields("CONCERN_NAME").Select vCompanies.Item(i).Text

Not applicable
Author

Hi

Thanks for your response.

I just tested

ActiveDocument.Fields("CONCERN_NAME").Select vCompanies.Item(i).Text

But it didn't help 😞 , same result.

Do you know the difference between field and fields. In the Api Doc, as I read it, I can only find Field.

Not applicable
Author

Hi

A small update from my own testing. If I replace:

set vCompanies = vCustomers.GetExcludedValues(10000)

with

set vCompanies = vCustomers.GetSelectedValues(10000)

it works as it should 🙂

But it shouldn't from a technical point of view matter which of these we use. Something for the support maybe.

Not applicable
Author

Hi

I did find the solution, a rather obvious one actually. But sometimes you are blind when looking at your own code.

Since I in the first one selects Excluded values, I only get values that are excluded.And since they are excluded I can't select them. If I cleared other selections after the getExludedValues it would be possible to select them.

I my case I didn't want to clear the other selections.

Working code:

vCustomers.SelectPossible

set vCompanies = vCustomers.GetSelectedValues(10000)

for i = 0 to vCompanies.Count-1

      set vCompanyName=vCompanies.Item(i)

     ActiveDocument.Fields("CONCERN_NAME").Select vCompanies.Item(i).Text

     vCurrency=ActiveDocument.GetField("CurrencyCode_Reporting").GetPossibleValues.Item(0).Text

     ActiveDocument.Fields("CurrencyCode").Select vCurrency

     call someMethod()

  next