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!

How to display messagebox saying no data to print ...VFP

Status
Not open for further replies.

arc42

Programmer
Sep 18, 2012
9
PH
Hello there!
I'm new in VFP, exactly 2 and a half weeks using VFP 9.0.
I have a grid, textboxes with labels, an Add command, Remove command and Print command.
When I click on an entry from the grid, then click the Print command, the report preview appears. But the problem is when there's no entry from the grid, and I click the Print command, the report preview still appears. I want to display a messagebox saying no data to print, instead. How can I achieve that?
I used this codes in the Print command:
IF VAL(thisform.grdTAcc.Tag) = 1
cReptitle = "INFORMATION"
SELECT tmp_accinst.* FROM tmp_accinst WHERE 1=2 INTO CURSOR tmp_report READWRITE
SELECT tmp_accinst
SCATTER MEMVAR
INSERT INTO tmp_report FROM MEMVAR
SELECT tmp_report
GO TOP
REPORT FORM rpt_access2 PREVIEW
SELECT tmp_report
USE
ELSE
MESSAGEBOX("No data to print! ",0+16,"User Message")
ENDIF
SELECT tmp_accinst
thisform.refresh

THANKS!!!
 
When you day "no data to print", I assume you mean that your Tmp_Report cursor is empty?

If so, you can test for it like this:

Code:
SELECT tmp_report
GO TOP
[b]IF EOF()
  MESSAGEBOX("No data to print! ",0+16,"User Message") 
ELSE[/b]
  REPORT FORM rpt_access2 PREVIEW
[b]ENDIF[/b]

I hope this makes sense.

(Welcome to VFP, by the way.)

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
To Mike,
Thank you for your response..

I've tried your given code, but unfortunately it didn't work..
I have this: thisform.grdTAcc.Tag = '1' on my init event.
But whenever I make it: thisform.grdTAcc.Tag = '0' , Only the messagebox"No data to print" appears, even if there were entries on the grid..


 
I don't understand the connection between thisform.grdTAcc.Tag and the empty cursor. However, if thisform.grdTAcc.Tag contains "0" in your Print code, that would explain why my code didn't work (because it never got executed) and why you saw the messagebox.

So, the question is: How did thisform.grdTAcc.Tag come to contain "0"? You must have stored that value somewhere in your code. You could trying doing a search of your code for that property to find where you are doing that (using the "All objects" option in the Find dialogue).

Alternatively, go to the Debugger, and set a breakpoint on that property (using "Break when an expression has changed"). If you don't know how to use the Debugger, read the relevant topics in the Help file.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
But the problem is when there's no entry from the grid

This is a wild guess since there is a LOT about what you are doing that hasn't been clarified, but are you saying that this problem occurs when your Grid's cursor (RecordSource) has no records in it?

If so, then you are going about this the wrong way.

You need to have records in your Grid's RecordSource - even if it is only one blank record.

Then you can COUNT how many records meet your print criteria or use a SQL Query to gather those printable records into a separate RptData cursor and use that as your test for whether or not you have records to print.

Good Luck,
JRB-Bldr






 
Hello...
I'm sorry to confuse you..I tried my best to find the error on my program..and finally, I knew it..
It's hard for me to discuss everything from my program...since I'm new in VFP. But fortunately I found the error and got the appropriate codes..
I really appreciated your suggestions...Thank you so much!!!
'Til next time..
 
>It's hard for me to discuss everything from my program
That's totally understandable.

The confusion begins, when you post code like "IF VAL(thisform.grdTAcc.Tag) = 1" without thisform.grdTAcc.Tag being explained at all.
As your further code copies the current tmp_accinst record into an empty cursor tmp_report you generate, it just depends on being on a record here, so Mikes EOF() test would be ok.
Also note you don't need to copy a record to print it, you can also use NEXT 1 in the REPORT FORM command to print the current 1 record:

Code:
SELECT tmp_accinst
IF !EOF("tmp_accinst")
   REPORT FORM rpt_access2 NEXT 1 PREVIEW
ENDIF

The only thing that eventually needs to change is your report control expressions should not address tmp_report, as you now print without copying a record into a seperate cursor, but simply print the current record of tmp_accinst

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top