Results 1 to 6 of 6
  1. #1
    beaurou is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    16

    opening PDF file

    What I want to acheive is to use a button to be able to open a pdf document using a search criteria base on a text box in a form. My text box name is Sig. This is where I stand:

    Private Sub Command24_Click()
    pat1 = """C:\Program Files (x86)\Adobe\Reader 10.0\Reader\AcroRd32.exe"""
    pat2 = "/A ""search= Me.sig"""
    pat3 = """C:\temp\p2p\icd rev c.pdf"""
    Shell pat1 & " " & pat2 & " " & pat3, vbNormalFocus
    End Sub



    everything work fine but I'm not able to pass the search criteria. Not able to point to the textbox.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    Add this code to a module (mine is modNATIVE)
    then you can open ANY document via its app.

    usage: OPENNATIVEAPP "c:\dir\file.pdf"
    (will open in acrobat)

    like OPENNATIVEAPP "c:\dir\file.doc"
    will open in Word.

    Code:
    'Attribute VB_Name = "modNativeApp"
    Option Compare Database
    Option Explicit
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
    Private Declare Function GetDesktopWindow Lib "user32" () As Long
    Const SW_SHOWNORMAL = 1
    Const SE_ERR_FNF = 2&
    Const SE_ERR_PNF = 3&
    Const SE_ERR_ACCESSDENIED = 5&
    Const SE_ERR_OOM = 8&
    Const SE_ERR_DLLNOTFOUND = 32&
    Const SE_ERR_SHARE = 26&
    Const SE_ERR_ASSOCINCOMPLETE = 27&
    Const SE_ERR_DDETIMEOUT = 28&
    Const SE_ERR_DDEFAIL = 29&
    Const SE_ERR_DDEBUSY = 30&
    Const SE_ERR_NOASSOC = 31&
    Const ERROR_BAD_FORMAT = 11&
    
    Public Sub OpenNativeApp(ByVal psDocName As String)
    Dim r As Long, msg As String
    r = StartDoc(psDocName)
    If r <= 32 Then
        'There was an error
        Select Case r
            Case SE_ERR_FNF
                msg = "File not found"
            Case SE_ERR_PNF
                msg = "Path not found"
            Case SE_ERR_ACCESSDENIED
                msg = "Access denied"
            Case SE_ERR_OOM
                msg = "Out of memory"
            Case SE_ERR_DLLNOTFOUND
                msg = "DLL not found"
            Case SE_ERR_SHARE
                msg = "A sharing violation occurred"
            Case SE_ERR_ASSOCINCOMPLETE
                msg = "Incomplete or invalid file association"
            Case SE_ERR_DDETIMEOUT
                msg = "DDE Time out"
            Case SE_ERR_DDEFAIL
                msg = "DDE transaction failed"
            Case SE_ERR_DDEBUSY
                msg = "DDE busy"
            Case SE_ERR_NOASSOC
                msg = "No association for file extension"
            Case ERROR_BAD_FORMAT
                msg = "Invalid EXE file or error in EXE image"
            Case Else
                msg = "Unknown error"
        End Select
    '    MsgBox msg
    End If
    End Sub
    Private Function StartDoc(psDocName As String) As Long
    Dim Scr_hDC As Long
    Scr_hDC = GetDesktopWindow()
    StartDoc = ShellExecute(Scr_hDC, "Open", psDocName, "", "C:\", SW_SHOWNORMAL)
    End Function

  3. #3
    beaurou is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    16
    My code work fine to open the pdf. I thik it is how to pass the pdf variable for the search

    pat2 = "/A ""search= Me.sig"""

    If I use

    pat2 = "/A ""search=exemple"""

    the pdf open and search for the word "exemple" in the pdf doc.

    what I what is to use a textbox to pass this info. And my text box name is Sig

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    I don't think VBA can pass parameter to the Adobe Acrobat search utility.

    VBA can open a PDF object and manipulate it. I have done this to split and merge PDF documents. Maybe the PDF object can be searched. I know data can be pulled from a form-fill PDF. Never tried to programmatically search an OCR PDF. AFAIK, for VBA to open and manipulate PDF object requires an install of Acrobat Professional. I do know my code works at the office where I have AcrobatPro but not at home where I do not have it.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    beaurou is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    16
    After several search I finaly found it and it work fine.

    Private Sub Command24_Click()
    strsrchstring = Me.Sig
    pat1 = """C:\Program Files (x86)\Adobe\Reader 10.0\Reader\AcroRd32.exe"""
    pat2 = "/A ""search=" & strsrchstring
    pat3 = """C:\temp\p2p\icd rev c.pdf"""
    Shell pat1 & " " & pat2 & " " & pat3, vbNormalFocus
    End Sub

    It open the pdf doc and use the textbox Sig for search string.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Amazing! Congratulations and thanks for sharing. Glad to know I was mistaken.

    I can see now that the issue was with not concatenating the Me.Sig variable. You don't really need the strSearch variable.

    Can do:
    pat2 = "/A ""search=" & Me.Sig

    I am testing with Reader 11.0 and doesn't quite work. The app opens but not the file.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Error on opening file
    By Sheba in forum Forms
    Replies: 5
    Last Post: 09-05-2014, 12:42 PM
  2. Opening a File
    By Mahendra1000 in forum Access
    Replies: 1
    Last Post: 01-24-2014, 07:45 AM
  3. Opening an existing xls file.
    By Jrw76 in forum Programming
    Replies: 1
    Last Post: 01-15-2014, 02:01 PM
  4. problem opening .mdb file
    By honeybee in forum Access
    Replies: 7
    Last Post: 06-25-2010, 11:33 AM
  5. Value List with opening a file.
    By seaper in forum Forms
    Replies: 0
    Last Post: 10-21-2009, 01:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums