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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Report previews ok - but prints from wrong table 1

Status
Not open for further replies.

DrAlbany

Programmer
Jun 14, 2003
46
GB
Hi Guys..,

I Really hope you can help, this is driving me crazy....

I have a data table "earnings" which holds err... earnings <grin> with things like date, person, amount etc..

I want to do a summary for a given date, so I run a query:-

SELECT Earnings.e_date_s;
FROM earnings;
GROUP BY Earnings.e_date_s;
ORDER BY Earnings.e_date_s DESC;
INTO TABLE data\tmp_date_summary.dbf

Group it all together and populate a grid with the list of dates for the user to select from.

When the user double clicks on the date, this trigers another sql statement to select all earnings for that date:-

SELECT Earnings.*, D_head.*;
FROM ;
earnings ;
LEFT OUTER JOIN d_head ;
ON Earnings.e_d_id = D_head.d_id;
WHERE Earnings.e_date_s = tmp_date_summary.e_date_s;
ORDER BY D_head.d_stage_n;
INTO TABLE c:\temp\tmp_dance_summary.dbf

d_head = header details for the dancers, so i can print their name along side the earnings...

Then run the report..... <pause for dramatic effect>

The report previews ok (even taken out the preview) but, when you click on the preview to zoom in/out or print the report, the report data source changes to the list of dates from "tmp_date_summary.dbf"

I have tried loads of different things (I don't give up easily)

Including:-

rewriting the report from scratch.
Making sure that I "SELECT" the correct table.
Add the tmp data table to the report.

I thought about closing the "date selection" form but I want to keep the date selection screen open so the user can print a different summary if need be.... just had an brain wave....


and It worked.... YEAH... I'm so happy.....
but i thought i would still post incase others have a similar problem, or somone can explain why this has happened....

I changed the recordsource to "" from the "date selection" form before running the second query, and put the recordsource back after the report printed.... i.e.

********************************
THISFORM.grid1.RecordSource = ""

SET SAFETY OFF
SELECT Earnings.*, D_head.*;
FROM ;
earnings ;
LEFT OUTER JOIN d_head ;
ON Earnings.e_d_id = D_head.d_id;
WHERE Earnings.e_date_s = tmp_date_summary.e_date_s;
ORDER BY D_head.d_stage_n;
INTO TABLE c:\temp\tmp_dance_summary.dbf

SET SAFETY ON

SELECT tmp_dance_summary

IF RECCOUNT("tmp_dance_summary") > 0
SET PRINTER TO NAME GETPRINTER()

REPORT FORM reports\dancer_summary PREVIEW
ELSE
=MESSAGEBOX("Sorry, no information to print",0+16,"No Data")
ENDIF

THISFORM.grid1.RecordSource = "tmp_date_summary"

******************************************



I hope this helps.....

Regards


Steve

Watch ya back, because some times the devil drives a minibus.
 
p.s. - Foxpro V8

Watch ya back, because some times the devil drives a minibus.
 
Steve,

Did you know that, when you give focus to a grid, VFP sometimes changes the selected record area to the cursor or table on which the grid is based?

This often causes problems where a report is launched from a grid, and the report expects its data to be in the currently selected work area. I'm not sure if that's what you are seeing, but it is a cause of many hard-to-find bugs.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
For lack of any reason other then insanity.

1. Does the report form have a data environment?
2. Does the report form use aliases before the field names?

David W. Grewe Dave
 
Hi Mike, thanks for your words of wisdom, it certainly looks like thats what it was/is doing.

Dave... I did set a data environment, and for the life of me can't remember if I set the table name before the variables.... it's something I normally do :) due to problems I have learnt to overcome with the report writer :)

Thanks again.

Regards


Steve

Watch ya back, because some times the devil drives a minibus.
 
Mike,

Your post about "disappearing table" interests me extremely. Just these days I've similar problems DrAlbany writes about.
Is there some other information available, or how one should fight against it? Avoiding grid.SetFocus() is enough?

Tom
 
Tom,

All you have to do is make sure the correct work area is selected immediately before you go into the report:

SELECT MyTable
REPORT FORM SomeReport .....

The report should then work correctly, even if it is executed from an event of the grid, such as a double-click.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Steve,
If you set a data environment in the report, then anything you do external to the report means almost nothing.

The report data environment will start a new data session, open the tables in the Environment and use that session and totaly disreguard the setting in the data session you called it from.

Copy your report to a save location, then removed the report data environment and give it a try.

David W. Grewe Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top