Qlik Community

Ask a Question

QlikView App Dev

Discussion Board for collaboration related to QlikView App Development.

Announcements
Join us at the Cloud Data and Analytics Tour! REGISTER TODAY
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Macro to loop through multiple fieldvalues

Hi,

I wrote a macro (VBS) to print a report to PDF and then mail it.

I need to loop through a field to generate a PDF report for each value and then get the email address associated (ie, the possible selection on the email field).

The code I wrote doesn't work as sometimes the current selections change when I try to get the possible values for the second field!

Can anyone point me in the right direction? thanks!

The same problem is already described in this post of 2010 (not answered)

Loop through multiple listBox selections and export to Excel

I'm sending a piece of the code I wrote below.

(...)

set mySelections = ActiveDocument.Fields(FieldName).GetPossibleValues(10000, True)
'Loop through FieldName
Dim i

    for i = 0 to mySelections.Count - 1

ActiveDocument.Fields(FieldName).Clear
ActiveDocument.Fields(EmailFieldName).Clear

ActiveDocument.GetApplication.WaitForIdle

        Dim FieldValue

        FieldValue = mySelections.Item(i).text

        ActiveDocument.Fields(FieldName).Select FieldValue

ActiveDocument.GetApplication.WaitForIdle

 

        Print_PDF FieldValue, reportName, in_ReportID, reportPath

       

' here is the line where the field selection changes

        set thisEmailSelection = ActiveDocument.Fields(EmailFieldName).GetPossibleValues(1)

       

        If thisEmailSelection.Count = 1 Then

       Dim EmailAddress
         EmailAddress = thisEmailSelection.Item(0).text

       If len(EmailAddress) > 10 Then     
  SendMail FieldValue, reportPath, reportName, in_ReportID, EmailAddress
  End If
     End If

   

   set thisEmailSelection = Nothing     

    Next

    set mySelections = Nothing   

   

end sub

Regards,

Marina Carvalho

1 Reply
Not applicable
Author

Hi

Perhaps this thread can shade som light on your issue:

Printing PDF's with a loop