printing a specific record

  • Thread starter Thread starter cckimball
  • Start date Start date
C

cckimball

How do I print a specific record in my report? I created
a database for everyone to enter information into. After
entering they're information they would like to print it
out in the report format that I created. How can they
print that specific record, and not the whole report?
 
This example assumes you have a primary key field named "ID" that uniquely
identifies the record you want to print.

The code in the Click event procedure for a command button to "print this
record" would look like this:

Private Sub cmdPrint_Click()
Dim strWhere As String

If Me.Dirty Then
Me.Dirty = False
End If
If Me.NewRecord Then
MsgBox "Pick a record to print."
Else
strWhere = "ID = " & Me.ID
DoCmd.OpenReport "MyReport", acViewNormal, , strWhere
End If
End Sub
 
Add a open report button on the form.



You have to set the record source for the report to an identifier of the
record, ex. transaction number.



So in your record source for your report you would have



SELECT * FROM tablename WHERE transaction number =
[Forms].[FormName]![transaction number]



I'm a newb, but i had something similar to this in a report I made.



Ryan
 
thanks for the help, but everytime I try to print an error
message pops up:

Run-time error '3075

Syntax error (missing operator) in query expression ' (Job
Code ID = MAN001)".

The line

DoCmd.OpenReport "JobDescriptionReport", acViewNormal,
strWhere

is highlighted as the problem line. Can you please help
me out?

Thanks
 
From someone on this list, more skilled than I am, I learned the following.
I do not know if this helps you but a report of a single record is printed.
Right click on black square to the left of the ruler. Choose Properties and
at Data, Data source click on the three small dots. In the new window draw
down from the list above the proper field name and write then on its
Condition line
=[Write the record#]
or a similar message. You will when starting your report get a message
"Write the record# to print".
Worked fine for me in Sweden, anyway!
/Ove
 
Allen was assuming that your ID field was the usual numeric
datatype. Since it is a String, you need to surround it with
single quotes. You also have the problem of having blanks in
your field names so you need to surround the name with
brackets. Try the following...

strWhere = "[Job Code ID] = '" & Me![Job Code ID] & "'"

Gary Miller
Sisters, OR
 
Back
Top