Printing a Specific Record

G

Guest

I have created a form that the user uses to enter information. I have read
several times that forms are not made to print from so I created an
indentical report that will be used.

I want to place a button on the form so that when the user is finished
entering the information they can click this button and print the report of
only the current record. When I created a command button to print the
report, it prints all records in the table.

How can I filter the report to print only the current record? Thank you in
advance.
 
G

Guest

You can filter your report using the Where argument of the OpenReport method.
You give it the name of the field in the report's record source you want to
filter on and the value you want to filter for. That is usually the name of
the control on your form that contains the value you want to filter for.

DoCmd.OpenReport "MyReport", , ,"[Field1] = " & Me.txtKeyValue

[Field1] is the name of the field in the report's record source.

txtKeyValue is the name of the control on the form that contains the value
you want to filter on.

This syntax assumes Field1 is a numeric field:
"[Field1] = " & Me.txtKeyValue

If it is a text field, use:
"[Field1] = '" & Me.txtKeyValue & "'"

If it is a date field, use:
"[Field1] = #" & Me.txtKeyValue & "#"
 

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