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. Advertisements

  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. Advertisements

  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. Advertisements

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. help!

    print a report for current record

    help!, Aug 12, 2004, in forum: Access Reports
    Replies:
    2
    Views:
    56
    Guest
    Aug 17, 2004
  2. Kate

    Print Report based on Current Record

    Kate, Oct 8, 2004, in forum: Access Reports
    Replies:
    0
    Views:
    67
  3. Lyle Davis
    Replies:
    9
    Views:
    86
  4. rml
    Replies:
    2
    Views:
    70
    Compuhelpmt
    Dec 11, 2005
  5. mphotographer via AccessMonster.com

    Is there a way to print only my current record and have it cover the sheet print

    mphotographer via AccessMonster.com, Jan 26, 2007, in forum: Access Reports
    Replies:
    2
    Views:
    112
    mphotographer via AccessMonster.com
    Jan 26, 2007
  6. Jean-Francois Gauthier

    report based on single record/prints current record only HELP!!!

    Jean-Francois Gauthier, Mar 9, 2007, in forum: Access Reports
    Replies:
    4
    Views:
    139
    evilcowstare via AccessMonster.com
    Mar 9, 2007
  7. Connie
    Replies:
    4
    Views:
    64
    Connie
    Jun 30, 2007
  8. Jackmac

    Print current record using a report form?

    Jackmac, Mar 10, 2008, in forum: Access Reports
    Replies:
    2
    Views:
    89
    Jackmac
    Mar 10, 2008
Loading...