Results 1 to 3 of 3
  1. #1
    StaceyE is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2015
    Posts
    1

    Close an open PDF file

    I have a module that loops through a file directory, opens the PDF files (Adobe Acrobat XI Standard), updates certain form fields and saves the document. It works like a charm. What I cannot seem to do if close a file before moving on to the next file. So I end up with a maximum number of PDF files open at one time and get errors. I've tried a few things I've found on the web but nothing is working! Here is the code I have that is doing everything right except closing the darn files.



    Public Sub FindReplacePDF()


    Dim AcroApp As Acrobat.AcroApp
    Dim theForm As Acrobat.AcroPDDoc
    Dim newForm As Acrobat.AcroPDDoc
    Dim strPath As String
    Dim strDoc As String
    Dim rsFlip As ADODB.Recordset


    strPath = "F:\SomeDocs"


    DoCmd.RunSQL ("Delete * FROM LocalFiles;")


    Call ListFilesToTable(strPath, , True)


    Set rsFlip = New ADODB.Recordset
    Set rsFlip.ActiveConnection = CurrentProject.Connection
    rsFlip.CursorType = adOpenKeyset
    rsFlip.LockType = adLockReadOnly


    rsFlip.Source = "SELECT * FROM LocalFiles ORDER BY FPath;"


    rsFlip.Open


    For intCount = 1 To rsFlip.RecordCount


    If rsFlip.Fields("FName") Like "*.PDF" And rsFlip.Fields("FName") Like "*ucc*" Then


    strDoc = rsFlip.Fields("FPath") & rsFlip.Fields("FName")

    Set AcroApp = CreateObject("AcroExch.App")
    Set theForm = CreateObject("AcroExch.PDDoc")
    Set newForm = CreateObject("AcroExch.PDDoc")
    StartDoc strDoc
    theForm.Open (strDoc)
    Set jso = theForm.GetJSObject

    Dim Field1, Field2, Field3, Field4, Field5, Field6 As Object

    Set Field1 = jso.getfield("4")
    Set Field2 = jso.getfield("5")
    Set Field3 = jso.getfield("6")
    Set Field4 = jso.getfield("7")
    Set Field5 = jso.getfield("8")
    Set Field6 = jso.getfield("10")

    Field1.Value = "text"
    Field2.Value = "more text"
    Field3.Value = "same"
    Field4.Value = "more same"
    Field5.Value = "even more text"
    Field6.Value = "this again"

    If theForm.Save(pdfsavefull, strdoc) = False Then
    theForm.Close
    Else
    newForm.Open (strdoc)
    newForm.Close
    End If


    AcroApp.Exit
    Set AcroApp = Nothing
    Set theForm = Nothing
    Set newForm = Nothing
    End If


    rsFlip.MoveNext
    Next intCount




    End Sub

  2. #2
    InsuranceGuy is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Aug 2015
    Location
    Colorado
    Posts
    126
    This isn't so much VBA as it is about the object you're creating. Check for a PDDocClose method on the "theForm" object.

    http://help.adobe.com/livedocs/pdfl_...l#PDDocClose()

    Cheers,


    Jeff

  3. #3
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Yeah, if you used an object to Open the PDF, use the same reference to the pddoc to close the file. Otherwise, you would have to use a Windows API to iterate all open windows and determine which are PDF files. I suppose the code you posted is doing this with Adobe Acrobat, but I am having difficulty following it. Seems there are some missing parts, maybe.

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

Similar Threads

  1. Why does Excel close when I open Access.
    By Bmadigan2000 in forum Access
    Replies: 1
    Last Post: 12-23-2013, 11:11 AM
  2. Replies: 6
    Last Post: 02-07-2013, 03:15 PM
  3. Replies: 1
    Last Post: 05-03-2012, 02:25 PM
  4. Using Access to open and close Excel
    By murfeezlaw in forum Programming
    Replies: 4
    Last Post: 04-04-2012, 07:58 PM
  5. DAO.Recordsets - When to close and open
    By jgelpi16 in forum Programming
    Replies: 11
    Last Post: 02-08-2011, 09:16 AM

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