DOCUMENT:Q185628 13-AUG-1999 [foxpro] TITLE :PRB: REPORT FORM TO PRINT Results in Incorrect Data PRODUCT :Microsoft FoxPro PROD/VER:MACINTOSH:3.0b; WINDOWS:3.0,3.0b,5.0,5.0a OPER/SYS: KEYWORDS: ====================================================================== ------------------------------------------------------------------------------- The information in this article applies to: - Microsoft Visual FoxPro for Macintosh, version 3.0b - Microsoft Visual FoxPro for Windows, versions 3.0, 3.0b, 5.0, 5.0a ------------------------------------------------------------------------------- SYMPTOMS ======== When a REPORT FORM TO PRINTER command is issued and a grid object has focus, incorrect data may be printed in the detail band of the report. CAUSE ===== When the REPORT FORM command is issued from either a toolbar or a menu, while a grid object has focus, the grid regains focus before the print job is completed. When the grid regains focus, the currently selected workspace is set to the record source associated with the grid. RESOLUTION ========== Here are three workarounds: - Add a command button with print functions to the form containing the grid. -or- - Create another form to accept the focus before printing. Here is a code example: oxprint=CREATEOBJECT(prtform) oxprint.SHOW DEFINE CLASS prtform AS FORM TOP = 50 LEFT = 50 HEIGHT = 2 WIDTH = 2 DOCREATE = .T. CAPTION = "" NAME = "Form2" PROCEDURE ACTIVATE * Insert REPORT FORM and any associated commands here. RELEASE THISFORM ENDPROC ENDDEFINE -or- - Create a user-defined function (UDF) that sets the workarea and reference the UDF in the report. A code example is shown below: PROCEDURE SETWORKAREA IF USED('mytable') SELECT mytable ENDIF retval=ALIAS() RETURN retval STATUS ====== Microsoft is researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available. MORE INFORMATION ================ Because the current workspace is effectively being reset to the grid's record source, the report is run using the record source associated with the grid. This behavior occurs even if the desired table or cursor is specified in the report's DataEnvironment. Steps to Reproduce Behavior --------------------------- WARNING: Running the following code may result in the printing of large reports spanning several pages. 1. Create a report, named Testgrid.frx, which contains the following fields: billings.line_no billings.unit_price billings.quantity 2. Save a copy of Testgrid.frx as Testwork.frx and add a field with the following expression: SETWORKAREA() 3. Create a program file named PRNDEMO, using the following code: CLOSE ALL OPEN DATABASE home()+"samples\data\testdata" USE orders IN 0 ocusttool=CREATEOBJECT('toolbars') ocusttool.SHOW ocustomer=CREATEOBJECT('customer') ocustomer.SHOW READ EVENTS PROCEDURE sqlqry cporder=orders.order_id SELECT orditems.line_no, orditems.unit_price, ; orditems.quantity ; FROM orditems ; WHERE orditems.order_id=cporder ; ORDER BY orditems.line_no ; INTO CURSOR billings PROCEDURE prnform PARAMETER prnout DO sqlqry IN PRNDEMO DO CASE CASE prnout="PREVIEW" REPORT FORM testgrid PREVIEW CASE prnout="WORKAROUND1" ; OR prnout="WORKAROUND2" REPORT FORM testgrid NOCONSOLE TO PRINT CASE prnout="WORKAROUND3" REPORT FORM testwork NOCONSOLE TO PRINT OTHERWISE REPORT FORM testgrid NOCONSOLE TO PRINT ENDCASE SELECT billings USE DEFINE CLASS prtform AS FORM TOP = 50 LEFT = 50 HEIGHT = 2 WIDTH = 2 DOCREATE = .T. CAPTION = "" NAME = "Form2" PROCEDURE ACTIVATE DO prnform IN PRNDEMO WITH "WORKAROUND2" RELEASE THISFORM ENDPROC ENDDEFINE DEFINE CLASS customer AS FORM TOP = 0 LEFT = 0 HEIGHT = 200 WIDTH = 385 DOCREATE = .T. CAPTION = "Click Form to Print Illustrate Problem" NAME = "Form1" ADD OBJECT grid1 AS GRID WITH ; COLUMNCOUNT = 12, ; HEIGHT = 72, ; LEFT = 25, ; RECORDSOURCE = "orders", ; RECORDSOURCETYPE = 1, ; TOP = 24, ; WIDTH = 335, ; NAME = "Grid1" ADD OBJECT command1 AS COMMANDBUTTON WITH ; LEFT=24, ; HEIGHT=100, ; CAPTION="Work Around \<1", ; TOP=100, ; WIDTH=335 PROCEDURE CLICK DO prnform IN PRNDEMO WITH "" ENDPROC PROCEDURE command1.CLICK DO prnform IN PRNDEMO WITH "WORKAROUND1" ENDPROC ENDDEFINE DEFINE CLASS toolbars AS TOOLBAR CAPTION = "Toolbar1" HEIGHT = 29 LEFT = 0 TOP = 0 WIDTH = 250 NAME = "toolbars" ADD OBJECT command1 AS COMMANDBUTTON WITH ; TOP = 4, ; LEFT = 6, ; HEIGHT = 22, ; WIDTH = 96, ; CAPTION = "\