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

andybrookeAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.