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

Need command line for preview and print Visual Foxpro 9

Status
Not open for further replies.

foamlady

Technical User
Mar 16, 2011
21
US
I have limited knowledge about FoxPro 9; but have done hours of trial and error. I need help with this as I have struggled now for many hours.Application: Form will be used for invoice at point of purchase. My form is working except for my preview and print command buttons. It is adding the record to my database and my report is working but the preview and the print does all records including the last record (that currently is on my screen/form). I only want to see and print the last recordIn old Fox Pro my command would be:REPORT FORMAT "C:\INVOICE.FRX" REST ENVIROMENT PREVIEW (rest meaning the last invoice)Thanks for your help.
 
If you look in your VFP Help for REPORT FORM you will see the various options.

REPORT FORM MyReportForm PREVIEW NOCONSOLE will preview the 'report'.

REPORT FORM MyReportForm TO PRINT NOCONSOLE will print the 'report'.

You can control the scope of the report by limiting the data table that you 'pass' to the report.

Code:
* --- Use Filter To Limit Report Data Records ---
SELECT MyRptData
SET FILTER TO <whatever limiting criteria>
REPORT FORM MyReportForm <whatever>
or
Code:
* --- Use SQL Query To Limit Report Data Records ---
SELECT *;
   FROM MyRptData;
   WHERE <whatever limiting criteria>;
   INTO CURSOR ThisRptData
SELECT ThisRptData
REPORT FORM MyReportForm <whatever>

There are a number of ways to do what you want.
Look at the VFP Help to get some understanding on the REPORT FORM command and its options.

And, as you can see above, there are a number of ways to limit the records 'passed' to the REPORT FORM.

Good Luck,
JRB-Bldr

 
Remove the ENVIRONMENT keyword.

REST should work for a scope, but NEXT 1 might be better since it doesn't move the record pointer.

What symptoms are you seeing? You say what you want, but not what's going wrong.
 
Dan,
What I get is a preview or print of the invoice report for every record in the database including the last entered-that's the one and only one I want to see and then print.

Jrbbldr,
I will definately study your suggestions, as I stated I'm really a newbie with a stick to it attitude. I do have a query in place that will bring up the record I want but I didn't know how to get it from that look (database) into my report.

Thanks guys, I know my terminology is really bad. I will keep posting my progress and if something I say clicks for any of you guys, great.
 
Have you tried any of the suggestions? Should we close our eyes and guess?
 
Dan,
No at that time last night I couldn't "try" anything, I was so excited to hear from someone with help that I wanted to respond.
Today I have taken the environment out tried the command with REST and still got all records.
I tried NEXT 1 and got only the first record.
Now, I will try some of the other suggestions. I do appreciate your help but I do apologize as I don't understand your last statement concerning close our eyes and guess.
 
The REPORT FORM command will work with a SCOPE option like NEXT 1 or REST

The Scope of NEXT 1 will only utilize the 'next 1 record' The confusing part is that the next 1 is in reality the current record.
Meaning that when the NEXT option is used, the Scope counter begins counting from the current record forward.

Good Luck,
JRB-Bldr




 
If Next 1 gives you the first record, then you're positioned on the first record when you call the report. (That's why I suggested trying it.) That also explains why REST gives you all records.

If you have a data environment in the report, you should probably get rid of it so the report uses the calling form's.

Another alternative is GO BOTTOM just before calling the report, but that's dangerous in a multi-user environment.
 
Actually the Scope option REST gives you the record where you are currently and then the 'rest' of the records.

So if you are at the TOP of the data table, then REST will give you ALL of the records.

Code:
SELECT MyData
GO TOP  && move to TOP of data table
REPORT FORM MyRptForm REST TO PRINTER NOCONSOLE

But if you have moved the record pointer to somewhere else in the data table then you get from that record and 'forward' to the end.

Code:
* --- Print only RECNO() >= 50 ---
SELECT MyData
GO 50  && move to record # 50
REPORT FORM MyRptForm REST TO PRINTER NOCONSOLE

Also note that if you have an active INDEX in effect on the data table, then your results may appear different since REST will be the same as 'all remaining records' from this point forward using the record sequence set up by the INDEX expression.

If you already know this stuff, I apologize for the suggestion, but for these sort of questions I often point people to look at the free on-line VFP tutorials at:
You might benefit from the videos:
Basic Reporting - Pt. 1
Basic Reporting - Pt. 2
Q&A: Using Related Tables In A Report
and any others that look interesting.

Good Luck,
JRB-Bldr
 
GO BOTTOM
REPORT FORMAT "C:\MYREPORT.FRX" PREVIEW

I still get a preview of all records.

(I'm the only user so that won't be a problem).

I understand that my cursor is pointing at the top record in my database when it is giving me all the records.

Back to "basics" I'm running a form to enter sales. I am in the form screen entering amounts and items (which I see is putting these entries into my showinvoice database. My customer needs to know the total so I use the command button preview which has the command (Do Preview.prg) and should show me a copy of the invoice that I am working with. Because I am entering amounts to the database through the form my cursor is sitting on the last entry in the database so why does it jump to the top when this program runs.

I have built a query called lastinvoice and when it works. I tried this morning to use it but with my beginning knowledge I couldn't write was needed to tell my invoice report to pull from this query.

I'll check out the online videos. My reports and forms are fine it's just this stickler. On the preview report there is the report tool bar and I can hit the "go to last" arrow and it works.


I will
 
REPORT FORM will only work from the current record if you add the REST option. In this regard REPORT FORM acts the same as SCAN, it will start from TOP, even if you GO BOTTOM first.

See the help on the Scope:

ALL
Include all records. (Default)

NEXT nRecords
Include the next nRecords number of records beginning with the current record.

RECORD nRecordNumber
Include only the specified record.

REST
Include a range of records beginning with the current record and ending with the last record.

Bye, Olaf.
 
Olaf,

thanks for responding and I think you understand that when my report runs it pulls the first record.
I want to see only the current record the one in the form I working with and/or the last one in the database and no "scope" fits that situation that I can find.

 
I want to see only the current record the one in the form I working with and/or the last one in the database and no "scope" fits that situation that I can find.

It depends on whether your Form has caused the Record Pointer to go to that single record in the data table.

If so - the the Scope option to use would be NEXT 1 since it would print only that one single record.
As in:
SELECT MyData
REPORT FORM MyRptForm NEXT 1 TO PRINTER NOCONSOLE

But if, for some reason, your data table record pointer was not precisely where you wanted it to be you could either:

Code:
* --- Make the record pointer go where needed ---
* --- And then print only the one record ---
SELECT MyData
LOCATE FOR CustomerID = 12345  && or some other criteria
REPORT FORM MyRptForm [B]NEXT 1[/B] TO PRINTER NOCONSOLE
OR
Code:
* --- Create a temporary cursor of only that one record ---
* --- And then print all records (although there is only one) ---
SELECT *;
   FROM MyData;
   WHERE CustomerID = 12345;
   INTO CURSOR RptData
SELECT RptData
REPORT FORM MyRptForm TO PRINTER NOCONSOLE

Good Luck,
JRB-Bldr
 
JRB,
Because I am entering field information on my form/screen that I want to see in the report I can't put in a locate in by program because it's being generated by my form screen.

You are so patient, thank you
 
foamlady,

The Scope REST does solve this, or RECORD nRecordNumber with the current (last) record number.

Bye, Olaf.
 
Because I am entering field information on my form/screen that I want to see in the report I can't put in a locate in by program because it's being generated by my form screen.

A REPORT FORM command runs off of a data table which is "pointed to" immediately before issuing the REPORT FORM command. It can print one or more records from that data table based on the methods we have discussed above.

If you are saying that your Form's data has not yet been entered into a data table before you attempt to print, then you will have to do so before you can get THAT specific data to print - even if that is into a different temporary Table/Cursor such as ThisRptData

Good Luck,
JRB-Bldr

 
You can store the record number to a variable and then you can:

STORE RECNO() TO m.rec
REPORT FORM yourreportname RECORD m.rec TO PRINTER NODIALOG NOCONS


That should do it too. Hope that helps.


Thanks,
J
 
GO BOTTOM
REPORT FORMAT "C:\MYREPORT.FRX" PREVIEW

I still get a preview of all records.

Of course you do! You've told it to do exactly that.

The default scope of REPORT FORM is ALL. By leaving out the scope entirely, as you've done here, you're explicitly saying ALL.

Put back the NEXT 1 scope (or *SOME* scope) if you want to limit the number of records included.
 
Foxup,
How do I set up a variable for the current record number?

My record number is a computer generated field on my form/screen.

Am I getting in over my head?
 
How do I set up a variable for the current record number?

To set an variable value equal to the current record number, you only need to use the Equal sign

Code:
SELECT MyData
nThisRecNo = RECNO()  && the variable now equals the current record number

BUT MORE IMPORTANTLY......

My record number is a computer generated field on my form/screen.

OK, lets get some terminology straight.

Form Textbox entries are not necessarily automatically written to a data table. They may be done so, but not necessarily.

If not, then you do NOT have a record containing the Form variable data. So with no record, you can have no record number.

You might want to use a command SET STEP ON just before the REPORT FORM command.

That new command will force the program to halt execution and automatically open the TRACE Window on the code.

At that point go to the Command Window and type BROWSE NORMAL
That will open a browse window to look at the data table which will be used by the immediately next REPORT FORM command.

Look in the Browse window to see where the cursor is (this is the current record). If this shows the data from your Form, then fine - use the NEXT 1 option in your REPORT FORM command.

If you cannot find your Form data at all, then it has not been written to the data table that the Report Form will run with.

Try that and get back to us.

Good Luck,
JRB-Bldr

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top