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

LOOP THRU CUST# LIST BOX AND PRINT SHEET

Want to automatically select each customer# in a LIST BOX and PRINT SHEET.

i.e. Select 1st Customer# and Print Sheet;

Select 2nd Customer# and Print Sheet;

etc.

How is this done? > MACRO?

11 Replies
biester
Specialist
Specialist

You could find a similar example here:

http://community.qlik.com/forums/p/20821/79887.aspx#79887

There we loop through an employees list box and export an object to excel. But you can replace the last lines of the macro with e. g.

ActiveDocument.Sheets(0).Print

(I didn't test latter, you should check APIGuide for correct syntax).

Rgds,
Joachim

Not applicable
Author

AWESOME!!!

Next> Want to:

1. Call QLIKVIEW from a DOS BATCH FILE with parameters

parm1: Doc Name

parm2: Customer Number

2. Open Doc; Select parm2 in Customer List Box; Print Sheet

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

See the "Command Line Syntax" in the Ref Guide. The approach is roughly this:

qv.exe /vCustnum=123 mydoc.qvw

Assign an OnOpen macro to the doc that:

-Get's the value of the Custnum variable
-Makes the selection and prints the sheet.

Note that the variable "Custnum" must be defined in the qvw for the qvw to receive the value.

-Rob

Not applicable
Author

Just to practice with variables:

Created List Box for field BRAND then,

1. Settings / Variable Overview > Added a variable named: vBRAND & assigned value ACUVUE 2

2. Displayed vBRAND in a List Box > Shows assigned value correctly.

3. Created Macro to make a selection in the BRAND List Box

Sub FOO400
ActiveDocument.Fields("BRAND").Clear
ActiveDocument.Fields("BRAND").Select(vBRAND)
end sub

Clear works but, nothing is selected! Using : Select ("ACUVUE 2") works fine

What is wrong?









rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP


ben6711 wrote: ActiveDocument.Fields("BRAND").Select(vBRAND)


You can't reference the QV variable directly in the macro. You must use an API call to retrieve it's value:

ActiveDocument.Fields("BRAND").Select(ActiveDocument.GetVariable("vBRAND").GetContent.String)

or not quite as precise, but less verbose:

ActiveDocument.Fields("BRAND").Select(ActiveDocument.Evaluate("vBRAND"))

-Rob

Not applicable
Author

Rob, Thank you!

Hope to hear more from you as I get further into the learning curve.

Ben

Not applicable
Author

RE: MACRO "FOO400b"

WORKS WHEN: 1. CALLED BY BUTTON

2. "OnOpen"

PROBLEMS WHEN CALLED FROM DOS COMMAND LINE:

1. D:\ qv.exe /vMyVarBRAND=ACUVUE D:\BEN01\QLIKVIEW\TABLEAU LaunchPad.qvw

ACUVUE IS SELECTED CORRECTLY IN LIST BOX BUT, NO PRINTING

2. D:\qv.exe /vMyVarBRAND=ACUVUE 2 D:\BEN01\QLIKVIEW\TABLEAU LaunchPad.qvw

DOC FAILS TO OPEN; TRIED: 'ACUVUE 2' and "ACUVUE 2" > NO SUCCESS

Sub FOO400b
ActiveDocument.Fields("BRAND").Clear

ActiveDocument.Fields("BRAND").Select(ActiveDocument.Evaluate("MyVarBRAND"))

activedocument.sheets("SH01").Printout
end sub



rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

If your qvw filename argument has a space in it, enclose the argument in double quotes.

"D:\BEN01\QLIKVIEW\TABLEAU LaunchPad.qvw"

-Rob

Not applicable
Author

Great! Can now successfully pass "ACUVUE 2"

Still have problem#1 > Print instruction not executed when Qlikview is started from DOS Command Line:

activedocument.sheets("SH01").Printout

Printing does happen when the macro is called by a button or, on Document Open!