Print Report only is text box has data

snagrat

Registered User.
Local time
Today, 12:13
Joined
Apr 2, 2002
Messages
61
I have the following code on my button

Private Sub cmdPrintQuote_Click()
'Open report Quote. Change to acViewNormal for printout
On Error GoTo macQuoteReport_Err

DoCmd.OpenReport "rptQuote", acPreview, "", ""

macQuoteReport_Exit:
Exit Sub

macQuoteReport_Err:
MsgBox Error$
Resume macQuoteReport_Exit
End Sub

However I only want the report to print if txtTotalPrice (also on the form) contains some data. Is this possible, and if so what code do I need to add??

Cheers
 
snagrat,

Code:
Private Sub cmdPrintQuote_Click() 
'Open report Quote. Change to acViewNormal for printout 
On Error GoTo macQuoteReport_Err 

If Nz(Me.txtTotalPrice, 0) <> 0 Then
   DoCmd.OpenReport "rptQuote", acPreview, "", "" 
   Exit Sub
End If

macQuoteReport_Exit: 
Exit Sub 

macQuoteReport_Err: 
MsgBox Error$ 
Resume macQuoteReport_Exit 
End Sub

Wayne
 
Works great, but can you explain what is meant by this line?

If Nz(Me.txtTotalPrice, 0) <> 0 Then

I understand that txtTotalPrice not equal to 0 then do so and so, but what does all the other info relate to (e.g. The Nz)?

Cheers
 
snagrat,

What you'll find out shortly is that there is
a value for a field (Null) that will get your
attention.

A field can be Null (EMPTY), "" (Nothing).

There is a BIG difference.

The Nz (see help) is a function that returns
something (in this case 0) if the field is
Null.

This avoids the agonizing message:

Illegal use of Null value.


Wayne
 

Users who are viewing this thread

Back
Top Bottom