Share via

How to preview or print only current record in report Microsoft Access

Anonymous
2013-01-17T09:10:54+00:00

everytime I want to preview or print current record it show all record in the database,

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

15 answers

Sort by: Most helpful
  1. Anonymous
    2013-01-17T12:18:45+00:00

    Firstly create a report based on the relevant table or query; do not print a form.  You then have two options to restrict the report to the current record by opening it from a form bound to the table or query:

    1.  Add two command buttons to the form and open the report in print preview or to send it to a printer.  If we assume for this example that the form is based on a Contacts table with a numeric primary key ContactID, and you've named the report rptContacts, to open the report in print preview the code would be:

    Const MESSAGETEXT = "No current record."

    Dim strCriteria As String

    strCriteria = "ContactID = " & Me.ContactID

    If Not IsNull(Me.ContactID) Then

        ' ensure current record is saved

        Me.Dirty = False

        ' open report in print preview

        DoCmd.OpenReport "rptContacts", _

            View:=acViewPreview, _

            WhereCondition:=strCriteria

    Else

        MsgBox MESSAGETEXT, vbExclamation, "Invalid Operation"

    End If

    For the button to print the report the code would be exactly the same, but the View argument of the OpenReport method would be omitted:

        DoCmd.OpenReport "rptContacts", _

            WhereCondition:=strCriteria

    2.  the alternative approach is to base the report on a query which includes a parameter on the ContactID column referencing the ContactID control on the form.  In query design view, assuming the form is named frmContacts, you'd out the following in the criteria row of the ContactID column:

    Forms!frmContacts!ContactID

    The code to open the report from the form would be as above, but omitting the WhereCondition argument of the OpenReport method, so to open the report in print preview would be;

        DoCmd.OpenReport "rptContacts", _

            View:=acViewPreview, _

    and to print the report:

        DoCmd.OpenReport "rptContacts"

    Tip:  if you put the following in the Activate event procedure of the report;

    DoCmd.Maximize

    and the following in its Deactivate event procedure:

    DoCmd.Restore

    the report will be maximized when you open it in print preview, and the normal window will be restored when you close it.

    Was this answer helpful?

    9 people found this answer helpful.
    0 comments No comments
  2. Anonymous
    2013-12-02T04:38:20+00:00

    There are two ways to do this. One way is to use the WHERE clause of the OpenReport method as Ken suggests. The other is to bind the report to a query which sets criteria to restrict the records returned. This is done by setting the criteria to reference the Key control on the form. A value in any control on an open form can be referenced using the syntax:

    Forms!formname!controlname

    Which method you choose to use depends on the structure and workflow of your application.

    In either case, you will need to specify the View parameter to either display or directly print the report.

    Thank you!  This is exactly what i have been searching for for nearly 4 hours! Now I can finally call it a day.

    I can't thank you enough.

    Sincerely,

    Jess

    Was this answer helpful?

    6 people found this answer helpful.
    0 comments No comments
  3. ScottGem 68,810 Reputation points Volunteer Moderator
    2014-03-09T22:24:48+00:00

    When you open a report in Print Preview mode it only shows the first page. There should be a navigation bar at the bottom that allows you to navigate to other pages. If you can do that, then those other pages will print.

    I don't see any filtering being done other than the join.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  4. Anonymous
    2013-12-25T09:53:51+00:00

    Thank you very much.

    I used your second option and it works perfectly.

    Was this answer helpful?

    0 comments No comments
  5. ScottGem 68,810 Reputation points Volunteer Moderator
    2013-01-17T12:58:25+00:00

    There are two ways to do this. One way is to use the WHERE clause of the OpenReport method as Ken suggests. The other is to bind the report to a query which sets criteria to restrict the records returned. This is done by setting the criteria to reference the Key control on the form. A value in any control on an open form can be referenced using the syntax:

    Forms!formname!controlname

    Which method you choose to use depends on the structure and workflow of your application.

    In either case, you will need to specify the View parameter to either display or directly print the report.

    Was this answer helpful?

    0 comments No comments