Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you code to print the current record in a report? 1

Status
Not open for further replies.

keysol

Programmer
Feb 27, 2001
81
CA
Hi,

I have a form where I put in a print command button using the wizard. It calls a report to print . The problem is that each and every record gets printed instead of just the current record.

What lines of code do I insert to limit the printing of reports to only the current record?

P.S. I had read somewhere in this forum where you use the following line:

DoCmd.OpenReport "", , , "Reçu # =" & Field "

I checked the datatable to look for a unique field. I found one called "receipt #". When I tried the line of code I ran into a problem because of the character #.

Gerr
 
Keysol,

DoCmd.OpenReport "YourReport",,, "[Reçµ #] = " & Me.YourField

The special characters make this a tougher thing. It is
assumed that your database field is numeric and unique.

Wayne
 
keysol (Programmer) Oct 1, 2003
Hi WayneRyan

I've tried what you suggested but I get an error message as follows:
Microsoft Access can't find '|' referred to in your expression.

Here's the code in my cmdButton:

Private Sub ImprimerRapport_Click()
On Error GoTo Err_ImprimerRapport_Click

Dim stDocName As String

stDocName = "Calendriers 2004"
'DoCmd.OpenReport stDocName, acNormal
DoCmd.OpenReport "YourReport", , , "[Numéro #]=" & [Me.Numéro #]

Exit_ImprimerRapport_Click:
Exit Sub

Err_ImprimerRapport_Click:
MsgBox Err.Description
Resume Exit_ImprimerRapport_Click

End Sub

As you can see I remmed-out the original DoCmd generated by the wizard.

Any idea what I'm doing wrong?

Gerr
 
Oops,

"YourReport" is replaced by "Calendriers_2004"

but it still gives me the same error message!

Gerr
 
Gerr,

I don't know about the special symbols, but I'll assume
that Access makes sense of them on your forms, etc.

You had the Me slightly misplaced.

Are you sure that the field is a number. I mean that in
the table it is defined as a number. Otherwise, you have
to add single-quotes:

DoCmd.OpenReport "YourReport",,,"[Num鲯 #] = '" & Me.[Num鲯 #] & "'"

Wayne
 
Hi WayneRyan,

Just to let you know I finally got it to work thanks to your suggestions. The final modification was as follows:

DoCmd.OpenReport "YourReport", , , "[Numéro #]=" & [Me.Numéro #]

DoCmd.OpenReport "YourReport", , , "[Numéro #]=" & Me.[Numéro #]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top