Print current record from form to report

R

rml

I have a form with the following code in a command button. I would like to
print that current record onto a report. It prints out the record on the
report but it also prints the all the records form the form. Does anyone
know what I'm doing wrong here?

Thanks.

Private Sub Command217_Click()
On Error GoTo Err_Command217_Click
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "aaa"

stLinkCriteria = "[ID]=" & Me![ID]
DoCmd.OpenReport stDocName, , , stLinkCriteria
DoCmd.DoMenuItem acFormBar, acFile, 6

Exit_Command217_Click:
Exit Sub

Err_Command217_Click:
MsgBox Err.Description
Resume Exit_Command217_Click

End Sub
 
C

Compuhelpmt

Yes, your query needs to be changed. In the criteria area of the primary key
field in the query design, enter the Forms!Nameofform fieldname
When you run the report, it will get the info from the query, which looks at
your form for the record you are highlighted on.
 

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