Solved Removing pages in report with Module (1 Viewer)

jazsriel

Member
Local time
Yesterday, 20:38
Joined
Dec 21, 2020
Messages
62
Hi, I know I have several problems I am working on at once, but each time a new one comes up it is more pressing than the previous one.

Right now I am using the following code in a database.

---------------------------------------------------------------------------------------------------------------------
Option Compare Database

Public Function DeletePages_FromPDF(ThisPDF As String, _
FromPage As Integer, _
Optional PageCount_ToDelete As Integer = 1) As String

' =================================================================
' Procedure Name: DeletePages_FromPDF
' Purpose: Delete several pages from a given file
' Procedure Kind: Sub
' Procedure Access: Public
' Parameter ThisPDF (String): The full path to the pdf file
' Parameter FromPage (Integer): start deleting from this page
' Parameter PageCount_ToDelete (Integer): Count of pages to be deleted.
' Omitting = only one page
' 0 = up to the end of pdf
' Returns Passed : Deletion was successful
' Failed : Deletion was failed
' Author: Kitayama
' Date: 2022/05/19
' =================================================================
On Error GoTo ErrorTrap

Dim PDDocSource As Object
Dim DeleteFrom As Integer
Dim DeleteTo As Integer
Dim cnt As Integer
Dim Msg As String

DeletePages_FromPDF = ""
Set PDDocSource = CreateObject("AcroExch.PDDoc")

' Open file
If PDDocSource.Open(ThisPDF) <> True Then
MsgBox "Unable to open the source PDF"
DeletePages_FromPDF = "Error"
GoTo ExitFunction
End If

cnt = PDDocSource.GetNumPages
If cnt > 1 Then

' Calculate Deleting pages
If PageCount_ToDelete = 0 Then PageCount_ToDelete = cnt - FromPage + 1
DeleteFrom = FromPage - 1
DeleteTo = DeleteFrom + (PageCount_ToDelete - 1)

' Start Deleting
If PDDocSource.DeletePages(DeleteFrom, DeleteTo) <> True Then
MsgBox "Unable to Delete " & ThisPDF
DeletePages_FromPDF = "Failed"
GoTo ExitFunction
Else
DeletePages_FromPDF = "Passed"
End If

' save the file
If PDDocSource.Save(&H1, ThisPDF) = False Then
MsgBox "Failed to Save Changes to " & ThisPDF
DeletePages_FromPDF = "Save Error"
End If
End If



ExitFunction:
' Application.Echo True
Exit Function
ErrorTrap:
Select Case Err.Number
Case Else
Msg = Err.Description
End Select
MsgBox Msg
Resume ExitFunction

End Function

However, the problem is, my report has 70+ pages in it and grows by 1 page every month. So unless I hit the button that callsfor this process it only deducts one page from the report. What I need is for the report to show just the previous month.

So this code is run on the 1st sometimes the 2nd of every month. I need it to only show the previous months report, not the current month or anything prior to the previous month. Hopefully, someone has an idea on this.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 09:38
Joined
May 7, 2009
Messages
19,226
i don't think you can do that on the pdf.
you need to tackle it on the root, the report.
just print the previous month.
 

jazsriel

Member
Local time
Yesterday, 20:38
Joined
Dec 21, 2020
Messages
62
It was working for almost 2 years, until this month it stopped working. It would process all the reports, and then it would remove all the extra ones. I have no idea why it stopped working.
 

jazsriel

Member
Local time
Yesterday, 20:38
Joined
Dec 21, 2020
Messages
62
This problem was solved in another post I made HERE. So thank you arnelgp.
 

Users who are viewing this thread

Top Bottom