Report printing

G

Guest

I have the following command button code to execute some instructions:
Private Sub prepare_invoicenumbers_Click()
On Error GoTo Err_prepare_invoicenumbers_Click
Dim stDocName As String
stDocName = "invoicenumbers"
DoCmd.RunMacro stDocName
stDocName = "endofmonthinvoicebie30p"
DoCmd.OpenReport stDocName, acNormal
stDocName = "endofmonthinvoiceclientsnonpool"
DoCmd.OpenReport stDocName, acNormal
stDocName = "invoicenumbersdelete"
DoCmd.RunMacro stDocName
Exit_prepare_invoicenumbers_Click:
Exit Sub
Err_prepare_invoicenumbers_Click:
MsgBox Err.Description
Resume Exit_prepare_invoicenumbers_Click
End Sub

My problem is that if the print command:
DoCmd.RunMacro stDocName
stDocName = "endofmonthinvoicebie30p"
get's executed, it's printing as well an empty page (or better just the
background) even if in the query, where the report gets it's data, is no
record at all.
How can I change the code so that it is NOT printing a report without record?
Thanks for your help
Klaus
 
G

Guest

Hi

Add some code to the report itself.

Private Sub Report_NoData(Cancel As Integer)
MsgBox "There is no data in this report"
Cancel = True
End Sub

Trap the error message if you get one

Hope this helps
 
G

Guest

Hi Wayne,
Can you please tell me where to enter your code?
Do you mean in the report properties > event > On no Data > Event procedure?
I tried that, but it's still printing.
Thanks
Klaus
 
G

Guest

I tried it again and it's ok - it says now "There is no data in this report".
- BUT now it's as well not printing the report withdata.
I use the following command button code to excecute some instructions. Now
it seems that, if in one report is no dat aswell the other one doesn't get
printed.
Any idea?
Thanks
Klaus
 
G

Guest

You put it on the OnNoData event in the report. This said I can't see your
RunMacro so this may be getting round the cancel.

If this is the case can you post the macro details
 
G

Guest

As we are all now to be PC and wanting to save the trees - for testing you
could change
DoCmd.OpenReport stDocName, acNormal
to
DoCmd.OpenReport stDocName, acPreview


Until it's sorted
 
G

Guest

Private Sub prepare_invoicenumbers_Click()
On Error GoTo Err_prepare_invoicenumbers_Click

Dim stDocName As String

stDocName = "invoicenumbers"
DoCmd.RunMacro stDocName
stDocName = "endofmonthinvoicebie30p"
DoCmd.OpenReport stDocName, acNormal
stDocName = "endofmonthinvoiceclientsnonpool"
DoCmd.OpenReport stDocName, acNormal
stDocName = "invoicenumbersdelete"
DoCmd.RunMacro stDocName
Exit_prepare_invoicenumbers_Click:
Exit Sub

Err_prepare_invoicenumbers_Click:
MsgBox Err.Description
Resume Exit_prepare_invoicenumbers_Click


End Sub
 
G

Guest

I changed, but the same - at first "there is no data in this report " and
than "The open report action was cancelled" - and it stops execution the rest
(to open and print the next report)
Klaus
 
G

Guest

OK you can use
On Error Resume Next
to restart the code after the 2501 error (cancel open/print)
 
G

Guest

Something like this


Private Sub prepare_invoicenumbers_Click()
On Error GoTo Err_prepare_invoicenumbers_Click
Dim stDocName As String
stDocName = "invoicenumbers"
DoCmd.RunMacro stDocName
stDocName = "endofmonthinvoicebie30p"
DoCmd.OpenReport stDocName, acNormal
stDocName = "endofmonthinvoiceclientsnonpool"
DoCmd.OpenReport stDocName, acNormal
stDocName = "invoicenumbersdelete"
DoCmd.RunMacro stDocName
Exit_prepare_invoicenumbers_Click:
Exit Sub
if err.number = 2501 then
' Do nothing here other than buy Wayne some big cakes
resume next
end if
End Sub
 
G

Guest

Would love to buy you some big cakes - BUT - the problem is that the code is
not working. If I use your altered code I get the message: "Compile error -
Label not defined.
If I use my old code and add your "IF" into it I have the same as before.
Any other idea?
Klaus
 
G

Guest

ooops - sorry typo (missing Err_prepare_invoicenumbers_Click)


Private Sub prepare_invoicenumbers_Click()
On Error GoTo Err_prepare_invoicenumbers_Click
Dim stDocName As String
stDocName = "invoicenumbers"
DoCmd.RunMacro stDocName
stDocName = "endofmonthinvoicebie30p"
DoCmd.OpenReport stDocName, acNormal
stDocName = "endofmonthinvoiceclientsnonpool"
DoCmd.OpenReport stDocName, acNormal
stDocName = "invoicenumbersdelete"
DoCmd.RunMacro stDocName
Exit_prepare_invoicenumbers_Click:
Exit Sub
Err_prepare_invoicenumbers_Click
If Err.Number = 2501 Then
' Do nothing here other than buy Wayne some big Very cakes
Resume Next
End If
End Sub


I just tried this and it works fine at my end -
 
G

Guest

I copied and paste your code again - now I have the following error message:
In the VB I have: "Err_prepare_invoicenumbers_Click" - highlighted - with
the error message: Compile error - Sub or Function not defined.
Klaus
 
G

Guest

ha ha ha getting too old for this :::::::

there is a missing :

should be
Err_prepare_invoicenumbers_Click:

sorry
 
G

Guest

You are not getting too old - I am getting more ansd more stupid (normally I
should have seen it.
Anyway now it's working - just one more question:
Is it possible that I can get rid of the message: "There is no data in this
report" ?
I just would like that, there where is data, the report prints - and for the
rest, where is no data, nobody is interested anyway - and so-with I do not
need an message.
Thanks for your help again.
Klaus
 
G

Guest

Problem solved - Thanks for all your help.

Amateur said:
You are not getting too old - I am getting more ansd more stupid (normally I
should have seen it.
Anyway now it's working - just one more question:
Is it possible that I can get rid of the message: "There is no data in this
report" ?
I just would like that, there where is data, the report prints - and for the
rest, where is no data, nobody is interested anyway - and so-with I do not
need an message.
Thanks for your help again.
Klaus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Report printing 1
Report printing problem 2
Printing report to PDF file 5
Report Missing Data 2
Previewing a report 7
Run Macro command 5
Slight Adjustment needed to Code 3
Command Button Not Executing 24

Top