Print Question

danbl

Registered User.
Local time
Today, 17:02
Joined
Mar 27, 2006
Messages
262
I have a macro that generates a report based on a query with a date range condition and a field value condition of -1. When the macro runs and both conditions are met I get what I want. However when the -1 condition fails, or is 0, I still get the report with #error which is to be expected.

I have tried using the where conditon field in the macro and set it so the field value is equal to -1 but I still get the report with the #Error.

Is there a way to not have the report print when the second condition is not -1???
 
What putting a criteria in the query? in the field where -1 is, place -1 in the criteria field...that way it won't see the 0.

just a quick thought. :)
 
The query has the -1 condition.
When the condition exists the report prints as expected. However when there is no data or 0, the report still is generated but shows no data with #Error in the calculation fields because there is no data. I am looking for a way to not have the report print when there is no data. I have tried an expression in the Where condition in the macro and also in the OnNo Data field in the report properties.

Any additional thoughts??
 
for what you want to do I think VB code would be your best option.
 
I am unfamiliar with VB code. How would I do this???
 
Depends on your macro and what you are exactly doing. If you are completely new to vb you might want to look at a few basic vba tutorials (such as If/else statements, working with recordsets) and then look into DoCmd vb for printing your report.

You can basically replace the majority of your macro with vb and have much more functionality.
 
Okay ..... I will check into the tutorials.

Thanks for pointing the right direction!
 
Your layout for your vba module might be something like this:

Dim db As database
Dim rs As dao.recordset
Dim qryresult as string

Set db = currentdb()
Set rs = db.openrecordset("yourqueryname")

'rs will now hold the answer to your query.

qryresult = rs![FieldName] 'moved answer of query to a variable for ease of use

If qryresult = 1 Then ' (change 1 to your good value for printing the report)
DoCmd.OpenReport "YourReportName"
Else
'Does nothing
End If



'Then just basically call the code from your macro. Replaces both your query and print report lines in your macro.
 
Last edited:
Thanks ......... I will give this a try and see what happens?????
 

Users who are viewing this thread

Back
Top Bottom