Print current record from form to report

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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.
 
Back
Top