Printing the currentrecord form a form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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.
 
Back
Top