Printing the currentrecord form a form

B

bmersereau

I have a form and a report that are pretty much identical. I want to create a cmd button to print the current record that is visible on the form. I am missing a piece and can't figure it out.
 
J

Jim/Chris

I got this from a prevfious post. It works fine.

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
field on your form that uniquely identifies the record is
CustID, you could use it to determine the where condition
as follows:

Dim strCriteria As String

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

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

Jim

-----Original Message-----
I have a form and a report that are pretty much identical.
I want to create a cmd button to print the current record
that is visible on the form. I am missing a piece and
can't figure it out.
 
¹

¹Ú¹®¼ö

Jim
Thank a ton, but I have one snag. The code you gave me worked great but I
get all [CustID]'s not just the current record. I would like to get the
report preview with only the current record selected in the form. Any
suggestioin?
Brad

Jim/Chris said:
I got this from a prevfious post. It works fine.

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
field on your form that uniquely identifies the record is
CustID, you could use it to determine the where condition
as follows:

Dim strCriteria As String

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

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

Jim

-----Original Message-----
I have a form and a report that are pretty much identical.
I want to create a cmd button to print the current record
that is visible on the form. I am missing a piece and
can't figure it out.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top