Print report of current record only

  • Thread starter Thread starter Emma
  • Start date Start date
E

Emma

I have the following code in the OnClick Event of a
command button and cannot get it to print only the report
for the current record. Can someone tell me where I have
gone awry?

Private Sub Print_Sponsorship_Consulting_Request_Click()
On Error GoTo
Err_Print_Sponsorship_Consulting_Request_Click

Dim stDocName As String, strLinkCriteria As String

'if Request Type is 1 then print the current record
Sponsorship Form
If Request_Type_Frame = 1 Then
stDocName = "Rpt_Sponsorship_Request"
'select only the current form accounting reference number
to the report accounting reference no.
strLinkCriteria = "Reports!
Rpt_Sponsorship_Request![Accounting_Reference_No] = Forms!
Frm_Request![Accounting_Reference_No]"
DoCmd.OpenReport stDocName, acPreview
Else

'if Request Type is 2 then print the current record
Consulting Form
If Request_Type_Frame = 2 Then
stDocName = "Rpt_Consulting_Request"
'select only the current form accounting reference number
to the report accounting reference no.
strLinkCriteria = "Reports!
Rpt_Consulting_Request![Accounting_Reference_No] = Forms!
Frm_Request![Accounting_Reference_No]"
DoCmd.OpenReport stDocName, acPreview
End If
End If


Thanks!

Emma
 
You set the value for strLinkCriteria, but you're not using it when you open
the report:

DoCmd.OpenReport stDocName, acPreview, strLinkCriteria

You might want to change how you define strLinkCriteria to:

strLinkCriteria = "[Accounting_Reference_No] = " &
Forms!Frm_Request![Accounting_Reference_No]
 
Okay,

Now I'm getting, "Data Type mismatch in criteria
expression."

Any idea what is causing this?
-----Original Message-----
You set the value for strLinkCriteria, but you're not using it when you open
the report:

DoCmd.OpenReport stDocName, acPreview, strLinkCriteria

You might want to change how you define strLinkCriteria to:

strLinkCriteria = "[Accounting_Reference_No] = " &
Forms!Frm_Request![Accounting_Reference_No]



--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Emma said:
I have the following code in the OnClick Event of a
command button and cannot get it to print only the report
for the current record. Can someone tell me where I have
gone awry?

Private Sub Print_Sponsorship_Consulting_Request_Click()
On Error GoTo
Err_Print_Sponsorship_Consulting_Request_Click

Dim stDocName As String, strLinkCriteria As String

'if Request Type is 1 then print the current record
Sponsorship Form
If Request_Type_Frame = 1 Then
stDocName = "Rpt_Sponsorship_Request"
'select only the current form accounting reference number
to the report accounting reference no.
strLinkCriteria = "Reports!
Rpt_Sponsorship_Request![Accounting_Reference_No] = Forms!
Frm_Request![Accounting_Reference_No]"
DoCmd.OpenReport stDocName, acPreview
Else

'if Request Type is 2 then print the current record
Consulting Form
If Request_Type_Frame = 2 Then
stDocName = "Rpt_Consulting_Request"
'select only the current form accounting reference number
to the report accounting reference no.
strLinkCriteria = "Reports!
Rpt_Consulting_Request![Accounting_Reference_No] = Forms!
Frm_Request![Accounting_Reference_No]"
DoCmd.OpenReport stDocName, acPreview
End If
End If


Thanks!

Emma


.
 
What's the data type of Accounting_Reference_No? If it's text, you need
quotes around the value:

strLinkCriteria = "[Accounting_Reference_No] = '" &
Forms!Frm_Request![Accounting_Reference_No] & "'"

Putting in extra spaces to make it more obvious:

strLinkCriteria = "[Accounting_Reference_No] = ' " &
Forms!Frm_Request![Accounting_Reference_No] & " ' "


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Okay,

Now I'm getting, "Data Type mismatch in criteria
expression."

Any idea what is causing this?
-----Original Message-----
You set the value for strLinkCriteria, but you're not using it when you open
the report:

DoCmd.OpenReport stDocName, acPreview, strLinkCriteria

You might want to change how you define strLinkCriteria to:

strLinkCriteria = "[Accounting_Reference_No] = " &
Forms!Frm_Request![Accounting_Reference_No]



--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Emma said:
I have the following code in the OnClick Event of a
command button and cannot get it to print only the report
for the current record. Can someone tell me where I have
gone awry?

Private Sub Print_Sponsorship_Consulting_Request_Click()
On Error GoTo
Err_Print_Sponsorship_Consulting_Request_Click

Dim stDocName As String, strLinkCriteria As String

'if Request Type is 1 then print the current record
Sponsorship Form
If Request_Type_Frame = 1 Then
stDocName = "Rpt_Sponsorship_Request"
'select only the current form accounting reference number
to the report accounting reference no.
strLinkCriteria = "Reports!
Rpt_Sponsorship_Request![Accounting_Reference_No] = Forms!
Frm_Request![Accounting_Reference_No]"
DoCmd.OpenReport stDocName, acPreview
Else

'if Request Type is 2 then print the current record
Consulting Form
If Request_Type_Frame = 2 Then
stDocName = "Rpt_Consulting_Request"
'select only the current form accounting reference number
to the report accounting reference no.
strLinkCriteria = "Reports!
Rpt_Consulting_Request![Accounting_Reference_No] = Forms!
Frm_Request![Accounting_Reference_No]"
DoCmd.OpenReport stDocName, acPreview
End If
End If


Thanks!

Emma


.
 
Back
Top