Print report of current record from form

  • Thread starter Thread starter Denis
  • Start date Start date
D

Denis

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,

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]
 
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,
 
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


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.


.
 
Back
Top