0 Replies Latest reply on Jan 25, 2018 2:09 AM by fmmm

    Adobe XI Pro and "The instruction at 0x refernced memory at 0x. The memory could not be read"


      Hello folks,


      We are generating PDF from MS Access within OLE Object - using Adobe Acrobat XI Pro Trial Version - the code seems working fine when in Debug Mode however in Non Debug it bugs with the following error "The instruction at 0x refernced memory at 0x. The memory could not be read".


      Tried many combinations but no luck - please help.


      Here is the code:


      Header 1

      Private Const GW_CHILD = 5

      Private Const GW_HWNDNEXT = 2



      Private Declare Function GetDesktopWindow Lib "user32" () As Long

      Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal _

      wCmd As Long) As Long

      Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _

      (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long



      Public Sub test()


          Dim dhwnd As Long      ' desktop window handle

          Dim hwnd As Long       ' window handle

          Dim rval As Long       ' return value

          Dim wname As String    ' window name

          Dim i As Integer

          Dim oXL As Excel.Application

          Dim oWD As Word.Application

          Dim oPP As PowerPoint.Application

          Dim ArcoApp As New Acrobat.AcroApp

          Dim OriPdf As Acrobat.CAcroPDDoc

          Dim avdoc As Acrobat.CAcroAVDoc

          Dim rootFolder As String

          Dim fileName As String

          Dim flag As Boolean


          Set rstSubForm = Forms!dbo_tblDokument!.Form.Recordset


          If CurrentProject.AllForms("dbo_tblDokument").IsLoaded Then

              rootFolder = "D:\Temp\Files\"


              Do While Not rstSubForm.EOF

                  With Forms!dbo_tblDokument!Inhalt

                      On Error Resume Next

                      If Forms!dbo_tblDokument!Inhalt.OLEType = acOLENone Then

                          GoTo last

                      End If


                      If Forms!dbo_tblDokument!DokuID > 68 Then

                          .Verb = acOLEVerbOpen

                          .Action = acOLEActivate

                          dhwnd = GetDesktopWindow()

                          hwnd = GetWindow(dhwnd, GW_CHILD)

                          flag = False


                          Do While hwnd <> 0

                              wname = Space(260)

                              rval = GetWindowText(hwnd, wname, 260)

                              wname = Left(wname, InStr(wname, Chr(0)) - 1)

                              Debug.Print wname

                              If Len(wname) Then


                                  If Trim(wname) Like "*Acrobat*" Then

                                      wbn = wname

                                      Set ArcoApp = CreateObject("AcroExch.App")

                                      Set OriPdf = CreateObject("AcroExch.PDDoc")

                                      fileName = rootFolder & Forms!dbo_tblDokument!DokuID & "_" & wname & ".pdf"

                                      If (Len(fileName) > 73) Then

                                          fileName = Left(fileName, 73)

                                      End If

                                      Debug.Print fileName

                                      Set avdoc = ArcoApp.GetActiveDoc

                                      If Not (avdoc Is Nothing) Then

                                          Set PdDoc = avdoc.GetPDDoc

                                          flag = PdDoc.Save(PDSaveFull, fileName)

                                      End If



                                      Exit Do

                                  End If

                              End If

                              hwnd = GetWindow(hwnd, GW_HWNDNEXT)


                          If flag = False Then

                              Debug.Print "Document with " & Forms!dbo_tblDokument!DokuID & " Document ID doesnt save"

                          End If

                      End If

                  End With






          End If

          MsgBox "Completed"

      End Sub