• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 269
  • Last Modified:

Filter a report coverting to PDF by client ID

Hi
I had a button that printed a report and in the VBA code it filtered the record to the customer that was active on the current form.

Dim stDocName, strWhere As String

    FormSaveRecord
    strWhere = "DMPClientID=" & Me!DMPClientID
    stDocName = "rptDMPFinancialStatementBlank"
    DoCmd.OpenReport stDocName, acPreview, , strWhere


I now have found (withh EE help) a module and code that coverts the report into a PDF

It works fine however the filter i use (ABOVE) is not working and when i use the code below it opens 40,000 pages and converts all of them instead of the 1 page filtered to the client ID

What can i add to the code below to filter it as the code above does?


Private Sub cmdReport2PDFSecurity_Click()

Dim blRet As Boolean

Dim tr As Long

tr = rsModify
tr = tr Or rsPrint
tr = tr Or rsCopyObj

blRet = ConvertReportToPDF(Me.lstRptName, vbNullString, _
Me.lstRptName.Value & ".pdf", False, True, 150, "ABC", "DEF", tr, 0)


End Sub

Open in new window

0
andybrooke
Asked:
andybrooke
  • 5
  • 3
1 Solution
 
Rey Obrero (Capricorn1)Commented:
try including the opening of the report in the click event of the button


Private Sub cmdReport2PDFSecurity_Click()

Dim blRet As Boolean

Dim tr As Long
Dim stDocName, strWhere As String

'    FormSaveRecord
    strWhere = "DMPClientID=" & Me!DMPClientID
    stDocName = "rptDMPFinancialStatementBlank"
    DoCmd.OpenReport stDocName, acPreview, , strWhere
tr = rsModify
tr = tr Or rsPrint
tr = tr Or rsCopyObj

blRet = ConvertReportToPDF(stDocName, vbNullString, _
Me.lstRptName.Value & ".pdf", False, True, 150, "ABC", "DEF", tr, 0)

docmd.close acreport stDocName
End Sub
0
 
andybrookeAuthor Commented:
Hi Capricorn
When I paste that code in VB the last line
'docmd.close acreport stDocName'
is coloured RED
0
 
Rey Obrero (Capricorn1)Commented:
forgot the comma

docmd.close acreport, stDocName
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
andybrookeAuthor Commented:
Hi.
I tried that and got errors. that was refering to Me.lstRptName.Value  part
I changed this to the report name and also changed stDocName to "rptDMPFinancialStatementBlank"
and deleted stDocName.
so code now:

Private Sub Command1136_Click()

Dim blRet As Boolean

Dim tr As Long
Dim stDocName, strWhere As String

'    FormSaveRecord
    strWhere = "DMPClientID=" & Me!DMPClientID
    DoCmd.OpenReport "rptDMPFinancialStatementBlank", acPreview, , strWhere
tr = rsModify
tr = tr Or rsPrint
tr = tr Or rsCopyObj

blRet = ConvertReportToPDF("rptDMPFinancialStatementBlank", vbNullString, _
"rptDMPFinancialStatementBlank" & ".pdf", False, True, 150, "ABC", "DEF", tr, 0)

DoCmd.Close acReport, stDocName

End Sub


But now i get a Out of Memory message.
0
 
andybrookeAuthor Commented:
Hi. sorted that memory problem out
(It was overload of the 40,000 PDF's i opened before so rebooted)

Tried again and it kind of workled just a couple little things.....

1st it opens the report twice.. once as a .rpt (access report format)
    2nd as a pdf
Q)  how do i stop it opening as a rpt and only as a PDF

2nd  after it has done all of this it then shows a error, when you go to debug the very last line is highlighted yellow.  'DoCmd.Close acReport, stDocName'
0
 
andybrookeAuthor Commented:
I have just deleted the last line and that seems to work.   what does the last line do?

if OK to delete only one more task and that is to get it not to show the rpt part
0
 
Rey Obrero (Capricorn1)Commented:
yuo got an error on this line
DoCmd.Close acReport, stDocName'

because you did this
 < and deleted stDocName. >
0
 
andybrookeAuthor Commented:
Dim blRet As Boolean

Dim tr As Long
Dim stDocName, strWhere As String

'    FormSaveRecord
    strWhere = "DMPClientID=" & Me!DMPClientID
    DoCmd.OpenReport "rptDMPFinancialStatementBlank", acPreview, , strWhere
tr = rsModify
tr = tr Or rsPrint
tr = tr Or rsCopyObj

blRet = ConvertReportToPDF("rptDMPFinancialStatementBlank", vbNullString, _
"rptDMPFinancialStatementBlank" & ".pdf", False, True, 150, "", "DEF", tr, 0)

DoCmd.Close acReport, "rptDMPFinancialStatementBlank"
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now