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

New Here ,
Jan 25, 2018 Jan 25, 2018

Copy link to clipboard

Copied

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\"

        rstSubForm.MoveFirst

        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

                                OriPdf.Close

                                ArcoApp.CloseAllDocs

                                Exit Do

                            End If

                        End If

                        hwnd = GetWindow(hwnd, GW_HWNDNEXT)

                    Loop

                    If flag = False Then

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

                    End If

                End If

            End With

           

           

last:

            rstSubForm.MoveNext

        Loop

    End If

    MsgBox "Completed"

End Sub

Capture.PNG
TOPICS
Acrobat SDK and JavaScript

Views

136

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
no replies

Have something to add?

Join the conversation