Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing from report preview gives "<cursor> is not related to the current work area"

Rajesh Karunakaran

Programmer
Joined
Sep 29, 2016
Messages
565
Location
MU
Hi dears,

In my 'SaveIt' method in the form, I save my invoice and updates all participating tables with TABLEUPDATE(). Then I call 'PrintIt' method. In that it calls 'send_to_preview' method which actually launches the report using 'REPORT FORM <report nam> PREVIEW'. Inside the report's "Init" method, I select the data needed for report and my final cursor is 'myRepData'. When it is prepared I explicitly select it as current alias using SELECT myRepData. Then I get the preview and its perfect.

However, when I click the print icon from the toolbar of the Preview window,
I get error message "myRepData is not related to the current work area".

This happens with both 'Private data session' on and off.

Anyone has any quick idea (if this is a known issue) as to what causes this problem?
 
There is no real Init in a report. A report based on a private datasession works based on the Table you set as "InitiallySelectedAlias", a report without private datasession works based on the workarea selected when you call REPORT FORM. So in both cases it makes no sense to select a workarea in code, the report driving workarea is already picked in both cases and that means you have to pick it these ways, either before REPORT FORM or - as you can't select a workarea of a new yet to be established datasession- in a private datasession report with the means of the initallyselectedalias property.

Educate me how it can work differently. Im aware in reportengine 90 you have means to switch alias in bands, but that's over the top, if you ask me. These two ways surely work.
 
What else to do: When the error itself pops up, pick "suspend" and see, if your preview run closes the report driving cursor at some point, perhaps in a report band like a footer or summary band. I don't see how else you get this error. Just be aware that preview and printing are two passes, you generate the output only once, the print run redoes the whole report and so there is not already fixed report output that's then just printed, you have to keep every workarea open until after the full report run including the print phase.
 
Hi Chriss

I am using the Init of DataEnvironment.
In the Init I am preparing the data cursor.
I am using 3 detail bands. After data preparations, at the end of the Init, my code is like below:

SELECT cInvoice && list of unique invoice ids which is the base of driving the report.
SET RELATION TO invoice_id INTO invoice_view && the main detail lines and many other details
SET RELATION TO invoice_id INTO cTaxComponents ADDITIVE && cursor of tax categories and amounts
SET RELATION TO invoice_id INTO cReceiptLineItems ADDITIVE && cursor of receipt details, cash, cheque etc with respective amounts
GO TOP

In fact, there are two things.
1. The preview is perfect.
2. If I print from outside, ie not from the preview itself, it prints perfect without any error.

One more point is that, I am closing all used cursors in the report in the DataEnvironment 'Destroy' method.
I have many other reports in which we do this same thing. But, in this one, failing to find out what causes this error!
 
Last edited:
Hi Chriss,

When I activated the 'Private Data Session', the problem solved !!!

But I am not fully getting the tech side of this as to how this change solves the problem.
(I am seeing references to this in your earlier replies, though)

Thanks
 
Hard to tell what's going on, as you earlier said you tried both private and non private datasession.
 

Part and Inventory Search

Sponsor

Back
Top