How to Print a report  based on some condition.

Posted on 2012-08-12
Last Modified: 2012-09-29
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.

Question by:Guidestar
    LVL 26

    Expert Comment

    Use the where clause of DoCmd.OpenReport.
    LVL 70

    Expert Comment

    Use a query and base the report on the output of the query.
    LVL 1

    Expert Comment

    I would use the suggestion by KCTS.
    LVL 30

    Accepted Solution

    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
          DoCmd.OpenReport "UnRegistered", acViewPreview, , "CustomerD = " & Me.CustomerID
    En IF

    Author Comment

    Hi Hnasr

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

    LVL 30

    Expert Comment

    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
          DoCmd.OpenReport "UnRegistered", acViewPreview, , "CustomerD = " & Me.CustomerID
    En IF

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

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    Suggested Solutions

    I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
    Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
    In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now