Avatar of rsburge
rsburge
Flag for United States of America

asked on 

Search for a Time in a PDF using VBA

Hi Experts - I am using the attached function in an Access database to search for today's date in a PDF.  I need help adjusting this code (or writing a new function) to search for today's date and a time and store the time in 24 hour format in a variable labled "pdfTime".  I will be using this variable to compare it to the current database time.

For example, if the date/time are showing in the PDF in any of the following formats, I need to make sure the date is today's date and then store the time in the variable "pdfTime" in the 24 hour format.  

10/4/2011 9:25 PM
10/4/11 9:25 PM
10/4/2011 21:25
10/4/11 21:25

The end purpose of the function I need is to compare the current date/time in a PDF to the current database time and return False if the date/time in the PDF are less than the current database date/time.
Public Function PDFdatecheck() As Boolean
SDdrive = Forms("frmFirewall").txtSDdriveLetter.Value
'-----CHECK PDF DATE-----'
    'IAC objects
    'DoCmd.Hourglass True
    Dim gAvDoc As Object
    
    'variables
    Dim Resp 'For message box responses
    Dim gPDFPath As String
    Dim sText1 As String 'String to search for
    Dim sText2 As String 'String to search for
    Dim sText3 As String 'String to search for
    Dim sText4 As String 'String to search for
    Dim sText5 As String 'String to search for
    Dim sText6 As String 'String to search for
    Dim sText7 As String 'String to search for
    Dim sText8 As String 'String to search for
    Dim sText9 As String 'String to search for
    Dim sText10 As String 'String to search for
    Dim sText11 As String 'String to search for
    Dim sText12 As String 'String to search for
    Dim sText13 As String 'String to search for
    Dim sStr As String 'Message string
    Dim foundText1 As Integer 'Holds return value from "FindText" method
    Dim foundText2 As Integer 'Holds return value from "FindText" method
    Dim foundText3 As Integer 'Holds return value from "FindText" method
    Dim foundText4 As Integer 'Holds return value from "FindText" method
    Dim foundText5 As Integer 'Holds return value from "FindText" method
    Dim foundText6 As Integer 'Holds return value from "FindText" method
    Dim foundText7 As Integer 'Holds return value from "FindText" method
    Dim foundText8 As Integer 'Holds return value from "FindText" method
    Dim foundText9 As Integer 'Holds return value from "FindText" method
    Dim foundText10 As Integer 'Holds return value from "FindText" method
    Dim foundText11 As Integer 'Holds return value from "FindText" method
    Dim foundText12 As Integer 'Holds return value from "FindText" method
    Dim foundText13 As Integer 'Holds return value from "FindText" method
    Dim Respi
    Dim Path As String
    
    'hard coding for a PDF to open, it can be changed when needed.
        'Path = SDdrive & ":\aLXE-Pricing\Reunion\Branch300.pdf"
    gPDFPath = filePath
 
    'Initialize Acrobat by creating App object
    Set gApp = CreateObject("AcroExch.App")
    gApp.Hide
        
    'Set AVDoc object
    Set gAvDoc = CreateObject("AcroExch.AVDoc")
        
    ' open the PDF
    If gAvDoc.Open(gPDFPath, "") Then
        sText1 = Format(Date, "mmmm d, yyyy") 'enter your searchstring here
        sText2 = Format(Date, "mmm-d-yyyy")  'enter your searchstring here
        sText3 = Format(Date, "mm/dd/yy")  'enter your searchstring here
        sText4 = Format(Date, "mm/dd/yyyy")  'enter your searchstring here
        sText5 = Format(Date, "m/d/yyyy")  'enter your searchstring here
        sText6 = Format(Date, "m/d/yy")  'enter your searchstring here
        sText7 = Format(Date, "mm_dd_yyyy")  'enter your searchstring here
        sText8 = Format(Date, "dddd, mmmm dd, yyyy")  'enter your searchstring here
        sText9 = Format(Date, "mmm-dd-yy")  'enter your searchstring here
        sText10 = Format(Date, "mmmm dd, yyyy")  'enter your searchstring here
        sText11 = Format(Date, "mmm dd, yyyy")  'enter your searchstring here
        sText12 = Format(Date, "mmm d, yyyy")  'enter your searchstring here
        sText13 = Format(Date, "d-mmm-yy")  'enter your searchstring here
        
        'FindText params: StringToSearchFor, caseSensitive (1 or 0), WholeWords (1 or 0), ResetSearchToBeginOfDocument (1 or 0)
        foundText1 = gAvDoc.FindText(sText1, 1, 0, 1) 'Returns -1 if found, 0 otherwise
        foundText2 = gAvDoc.FindText(sText2, 1, 0, 1) 'Returns -1 if found, 0 otherwise
        foundText3 = gAvDoc.FindText(sText3, 1, 0, 1) 'Returns -1 if found, 0 otherwise
        foundText4 = gAvDoc.FindText(sText4, 1, 0, 1) 'Returns -1 if found, 0 otherwise
        foundText5 = gAvDoc.FindText(sText5, 1, 0, 1) 'Returns -1 if found, 0 otherwise
        foundText6 = gAvDoc.FindText(sText6, 1, 0, 1) 'Returns -1 if found, 0 otherwise
        foundText7 = gAvDoc.FindText(sText7, 1, 0, 1) 'Returns -1 if found, 0 otherwise
        foundText8 = gAvDoc.FindText(sText8, 1, 0, 1) 'Returns -1 if found, 0 otherwise
        foundText9 = gAvDoc.FindText(sText9, 1, 0, 1) 'Returns -1 if found, 0 otherwise
        foundText10 = gAvDoc.FindText(sText10, 1, 0, 1) 'Returns -1 if found, 0 otherwise
        foundText11 = gAvDoc.FindText(sText11, 1, 0, 1) 'Returns -1 if found, 0 otherwise
        foundText12 = gAvDoc.FindText(sText12, 1, 0, 1) 'Returns -1 if found, 0 otherwise
        foundText13 = gAvDoc.FindText(sText13, 1, 0, 1) 'Returns -1 if found, 0 otherwise
    Else
        ' if failed, show error message
        'Resp = MsgBox("Cannot open" & gPDFPath, vbOKOnly)
        PDFdatecheck = True
        gAvDoc.BringToFront
         Sleep 2000
         SendKeys ("^q"), True   'exit document
         Sleep 1500
        On Error Resume Next
        gApp.Exit
        Set gAvDoc = Nothing
        Set gApp = Nothing
        'numberlock
        Exit Function
    End If
 
 If foundText1 = -1 Or foundText2 = -1 Or foundText3 = -1 Or foundText4 = -1 Or foundText5 = -1 Or foundText6 = -1 Or foundText7 = -1 Or foundText8 = -1 Or foundText9 = -1 Or foundText10 = -1 Or foundText11 = -1 Or foundText12 = -1 Or foundText13 = -1 Then
        'compose a message
        'sStr = "Rates are Current"
        'Resp = MsgBox(sStr, vbOKOnly)
        gAvDoc.BringToFront
        Sleep 2000
        SendKeys ("^q"), True   'exit document
        Sleep 1500
        On Error Resume Next
        gApp.Exit
        Set gAvDoc = Nothing
        Set gApp = Nothing
        'SendKeys ("{ENTER}"), True   'exit document
  Else
        ' if failed, show error message
        'Resp = MsgBox("Today's Rates Not Available Yet", vbOKOnly)
        PDFdatecheck = True
        gAvDoc.BringToFront
         Sleep 2000
         SendKeys ("^q"), True   'exit document
         Sleep 1500
        On Error Resume Next
        gApp.Exit
        Set gAvDoc = Nothing
        Set gApp = Nothing
    End If
End Function

Open in new window

Visual Basic ClassicProgramming

Avatar of undefined
Last Comment
Chris Raisin

8/22/2022 - Mon