Print report of current record from form

Discussion in 'Access Reports' started by Denis, May 8, 2004.

  1. Denis

    Denis Guest

    How can I create a command button in a form to print a
    report containing data only from the current record In
    Access 2003? The pertinent macro attached to the Command
    Button wizard prints reports for all the records. I would
    like to restrict it to the current record only.

    Thanks, Denis.
    Denis, May 8, 2004
    #1
    1. Advertising

  2. Denis,

    In the Where Condition argument of the OpenReport macro action, put the
    equivalent of...
    [ID]=[Forms]![NameOfForm]![ID]
    (where ID is the primary key or otherwise field which uniquely
    identifies each record in your form and report).

    Another approach is to use a query as the record source for the report,
    and in the criteria of the ID (or equivalent) field in the query, refer
    to the current record in the form, e.g.
    [Forms]![NameOfForm]![ID]

    --
    Steve Schapel, Microsoft Access MVP


    Denis wrote:
    > How can I create a command button in a form to print a
    > report containing data only from the current record In
    > Access 2003? The pertinent macro attached to the Command
    > Button wizard prints reports for all the records. I would
    > like to restrict it to the current record only.
    >
    > Thanks, Denis.
    Steve Schapel, May 8, 2004
    #2
    1. Advertising

  3. Denis,

    You will need to add a Where Condition to the OpenReport method so that the
    report shows only the information for the record displayed on your form. For
    example, if the current record on your form was for a particular customer,
    you could use the CustID field to determine the where condition as follows:

    Dim strCriteria As String

    ' This works when your matching field is text
    strCriteria = "[CustID] = " & Chr(34) & Me!CustID & Chr(34)
    DoCmd.OpenReport "MyReport", acViewNormal, , strCriteria

    ' This works when your matching field is a number
    strCriteria = "[CustID] = " & Me!CustID
    DoCmd.OpenReport "MyReport", acViewNormal, , strCriteria

    hth,


    --

    Cheryl Fischer, MVP Microsoft Access
    Law/Sys Associates, Houston, TX


    "Denis" <> wrote in message
    news:a26201c434b6$0d405a70$...
    > How can I create a command button in a form to print a
    > report containing data only from the current record In
    > Access 2003? The pertinent macro attached to the Command
    > Button wizard prints reports for all the records. I would
    > like to restrict it to the current record only.
    >
    > Thanks, Denis.
    Cheryl Fischer, May 8, 2004
    #3
  4. Denis

    Denis Guest

    Thanks a lot. It worked!!!

    Denis

    >-----Original Message-----
    >Denis,
    >
    >You will need to add a Where Condition to the OpenReport

    method so that the
    >report shows only the information for the record

    displayed on your form. For
    >example, if the current record on your form was for a

    particular customer,
    >you could use the CustID field to determine the where

    condition as follows:
    >
    > Dim strCriteria As String
    >
    > ' This works when your matching field is text
    > strCriteria = "[CustID] = " & Chr(34) & Me!CustID &

    Chr(34)
    > DoCmd.OpenReport "MyReport", acViewNormal, ,

    strCriteria
    >
    > ' This works when your matching field is a number
    > strCriteria = "[CustID] = " & Me!CustID
    > DoCmd.OpenReport "MyReport", acViewNormal, ,

    strCriteria
    >
    >hth,
    >
    >
    >--
    >
    >Cheryl Fischer, MVP Microsoft Access
    >Law/Sys Associates, Houston, TX
    >
    >
    >"Denis" <> wrote in

    message
    >news:a26201c434b6$0d405a70$...
    >> How can I create a command button in a form to print a
    >> report containing data only from the current record In
    >> Access 2003? The pertinent macro attached to the

    Command
    >> Button wizard prints reports for all the records. I

    would
    >> like to restrict it to the current record only.
    >>
    >> Thanks, Denis.

    >
    >
    >.
    >
    Denis, May 8, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Anita
    Replies:
    4
    Views:
    288
    Augusto Senesi
    May 2, 2010
  2. Angie
    Replies:
    0
    Views:
    61
    Angie
    Feb 3, 2006
  3. Ricoy-Chicago
    Replies:
    1
    Views:
    37
    fredg
    Mar 7, 2005
  4. Beverly76

    Print Report Record Matching Current Form

    Beverly76, Dec 19, 2005, in forum: Access Forms
    Replies:
    2
    Views:
    35
    fredg
    Dec 19, 2005
  5. Bob Loder

    Print Report of Current Record Shown on Form

    Bob Loder, Oct 14, 2003, in forum: Access Beginners
    Replies:
    6
    Views:
    43
    Joan Wild
    Oct 15, 2003
Loading...

Share This Page