• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 206
  • Last Modified:

How to Print a report based on some condition.

Hi Everyone

I have two types of Customers in my Access 2010 database, Registered and Unregistered identified by a logical field.
i need to print two types of Certificates for Registered and Unregistered Customers.

How can control certificate Report printing  for Registered Customer and Unregistered Customer.

Thanks
0
Guidestar
Asked:
Guidestar
1 Solution
 
MacroShadowCommented:
Use the where clause of DoCmd.OpenReport.
0
 
KCTSCommented:
Use a query and base the report on the output of the query.
0
 
SimbaBiehlCommented:
I would use the suggestion by KCTS.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
hnasrCommented:
How do you issue the order to print the certificate?
Is this by clicking a button on a form showing that customer's record?

If Me.reg_unreg_field = "Registered" Then
      DoCmd.OpenReport "Registered", acViewPreview, , "CustomerD = " & Me.CustomerID
Else
      DoCmd.OpenReport "UnRegistered", acViewPreview, , "CustomerD = " & Me.CustomerID
En IF
0
 
GuidestarAuthor Commented:
Hi Hnasr

if the conditional part exists on the subform then instead of using Me how do we reference the field on it.

thanks
0
 
hnasrCommented:
Me is used in code to refer to the current form that has the code running.
To reference a field in the current form: Me.fieldInSameForm
To reference field on subform: Me!subformControl.Form.fldname
   The last line means the "fieldname" of the "Form" that was dragged to the main form and given or named as subformControl

So code is modified as:

If Me.subformControl.Form.reg_unreg_field = "Registered" Then
      DoCmd.OpenReport "Registered", acViewPreview, , "CustomerD = " & Me.CustomerID
Else
      DoCmd.OpenReport "UnRegistered", acViewPreview, , "CustomerD = " & Me.CustomerID
En IF

The same is done for CustomerID if it is on subform.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now