Print One Record From Form

  • Thread starter Thread starter Don
  • Start date Start date
D

Don

I have a form with a button that should allow me to print a report for only
the record on the form with the corresponding link criteria. in the On Click
Event Procedure I have the following code:

Private Sub Print_Audit_Report_Click()
On Error GoTo Err_Print_Audit_Report_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Audit Open Projects"
stLinkCriteria = "[CDCNum]=" & Me![Project Name]

'On Both Form and Report the property name is Project Name and Control
Source is CDCNum

DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria

Exit_Print_Audit_Report_Click:
Exit Sub

Err_Print_Audit_Report_Click:
MsgBox Err.Description
Resume Exit_Print_Audit_Report_Click

End Sub

What happens when I try to execute the code is a window pops-up telling me
"Enter Parameter Value". I then enter A12345 (the CDCNum and Project Name)
and the correct record is printed in the report. Any suggestions on what is
going wrong?

Thanks,

Dennis
 
Thanks I found the anwser

DoCmd.OpenReport "Audit Open Projects", acViewPreview, , "[CDCNum] = '" &
[CDCNum] & "'"
 
Here's a bit more detail on the technique, Don:
Print the record in the form
at:
http://allenbrowne.com/casu-15.html

Ensures any edits are saved first.
Makes sure the form is not at a new record.
Explains handling Number verses Text fields.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Don said:
Thanks I found the anwser

DoCmd.OpenReport "Audit Open Projects", acViewPreview, , "[CDCNum] = '" &
[CDCNum] & "'"

--
Thanks,

Dennis


Don said:
I have a form with a button that should allow me to print a report for
only
the record on the form with the corresponding link criteria. in the On
Click
Event Procedure I have the following code:

Private Sub Print_Audit_Report_Click()
On Error GoTo Err_Print_Audit_Report_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Audit Open Projects"
stLinkCriteria = "[CDCNum]=" & Me![Project Name]

'On Both Form and Report the property name is Project Name and Control
Source is CDCNum

DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria

Exit_Print_Audit_Report_Click:
Exit Sub

Err_Print_Audit_Report_Click:
MsgBox Err.Description
Resume Exit_Print_Audit_Report_Click

End Sub

What happens when I try to execute the code is a window pops-up telling
me
"Enter Parameter Value". I then enter A12345 (the CDCNum and Project
Name)
and the correct record is printed in the report. Any suggestions on what
is
going wrong?

Thanks,

Dennis
 
Back
Top