Print report of current record only

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
 
D

Douglas J. Steele

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]
 
G

Guest

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


.
 
D

Douglas J. Steele

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


.
 

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