Print Preview a Report Button

K

Keith

I added a Print Preview button with the wizard and modified it so that it
would only print the report for the record I was on, but I am having
problems.

My code is below.

The field containing the unique value of the record is
Code:
 and the first
record in the database (for example) contains the value A001 in this field.

However, when I click Print Preview, it asks for a parameter for A001 and I
have to enter the code I want to view the report for.

Why would this be?
 
A

Allen Browne

The issue could be that your primary key field is Text (not number), so
extra quote marks are needed as the delimiter:

Private Sub cmdPreview_Click()
Dim strWhere As String

If Me.Dirty Then 'Save first.
Me.Dirty = False
End If
If Me.NewRecord Then
MsgBox "Select a record to print"
Else
strWhere = "Code = """ & Me.Code & """"
DoCmd.OpenReport "MyReport", acViewPreview, , strWhere
End If
End Sub
 
K

Keith

Thank you for your help

Allen Browne said:
The issue could be that your primary key field is Text (not number), so
extra quote marks are needed as the delimiter:

Private Sub cmdPreview_Click()
Dim strWhere As String

If Me.Dirty Then 'Save first.
Me.Dirty = False
End If
If Me.NewRecord Then
MsgBox "Select a record to print"
Else
strWhere = "Code = """ & Me.Code & """"
DoCmd.OpenReport "MyReport", acViewPreview, , strWhere
End If
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Keith said:
I added a Print Preview button with the wizard and modified it so that it
would only print the report for the record I was on, but I am having
problems.

My code is below.

The field containing the unique value of the record is
Code:
 and the
first
record in the database (for example) contains the value A001 in this
field.

However, when I click Print Preview, it asks for a parameter for A001 and
I
have to enter the code I want to view the report for.

Why would this be?[/QUOTE]
[/QUOTE]
 

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