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