Late Binding (1 Viewer)

Sun_Force

Active member
Local time
Tomorrow, 06:20
Joined
Aug 29, 2020
Messages
396
The following code is a part of a function and it works if I add an Acrobat reference.

SQL:
    Dim AcroPDDocNew As New Acrobat.AcroPDDoc
    Dim Ret As Long

    Ret = AcroPDDocNew.Create()
    Ret = AcroPDDocAdd.Open("D:\Downloads\P0502.pdf")

When I share the database with a friend who has not Acrobat Pro, he receives a missing reference error.
How can I change it to late binding?

I tried the following but received a "ActiveX Component can not create object" error.
SQL:
    Dim AcroPDDocNew  As Object
    Set AcroPDDocNew  = CreateObject("Acrobat.Application")
 
Last edited:

Sun_Force

Active member
Local time
Tomorrow, 06:20
Joined
Aug 29, 2020
Messages
396
Is there any other choice?
Can I add/remove references with vba?
 

Sun_Force

Active member
Local time
Tomorrow, 06:20
Joined
Aug 29, 2020
Messages
396
Late Binding won't help if they don't have Acrobat Pro.
Yes I know. The point is those who share the database won't run the mentioned function.
So if I change it to late binding, it works for me and they'll be able to open the database and do whatever they want.

I'm just trying to hide the error at startup for them.


Edit: To be more clear, it's a test database shared between the students of a collage. So others need to work on it. But don't need to run all functions.
 
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 05:20
Joined
May 7, 2009
Messages
19,229
if some don't have Adobe Pro, you can discard your code.
instead use:

Application.FollowHyperlink "D:\Downloads\P0502.pdf"

it will open in the browser, if they don't have any pdf reader.
 

Sun_Force

Active member
Local time
Tomorrow, 06:20
Joined
Aug 29, 2020
Messages
396
@arnelgp they don't need to open the file or run the code.
The moment they launch the database they receive a missing reference error. and everything stops.

I just need to make the db work as if there's no reference to acrobat.

thanks
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 05:20
Joined
May 7, 2009
Messages
19,229
Code:
'https://bytes.com/topic/access/answers/210488-how-delete-missing-references-vba
Public Function RemoveBrokenReference()
Dim refCurr As Access.Reference
Dim intCount As Integer

For intCount = Access.References.count To 1 Step -1
    Set refCurr = Access.References(intCount)
    If Not refCurr.BuiltIn Then
        If refCurr.IsBroken Then
            Access.References.Remove refCurr
        End If
    End If
Next
End Function
 

Sun_Force

Active member
Local time
Tomorrow, 06:20
Joined
Aug 29, 2020
Messages
396
Code:
'https://bytes.com/topic/access/answers/210488-how-delete-missing-references-vba
Public Function RemoveBrokenReference()
Dim refCurr As Access.Reference
Dim intCount As Integer

For intCount = Access.References.count To 1 Step -1
    Set refCurr = Access.References(intCount)
    If Not refCurr.BuiltIn Then
        If refCurr.IsBroken Then
            Access.References.Remove refCurr
        End If
    End If
Next
End Function

Still three problems remains :

1- I think if I can use late binding of acrobat, it's much easier, faster and cleaner. (I'm still waiting for a solution on that)
2- Even when I use the above code, I receive the missing reference error. It seems references are checked sooner than autoexec.
3- Even if I run the code manually, I receive the error : "Can't find the saved reference".
on Access.References.Remove refCurr



Thanks
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 05:20
Joined
May 7, 2009
Messages
19,229
use Late binding as you did on your previous post.
add error handler to your function so you will not get runtime error, eg:


...
...
Dim AcroPDDocNew As Object
On Error Goto Err_Handler:
Set AcroPDDocNew = CreateObject("Acrobat.Application")
..
..
Graceful_Exit:
Exit Function

Err_Handler:
Msgbox Err.Number & vbCrLf & Err.Description
Resume Graceful_Exit
End Function
 

Sun_Force

Active member
Local time
Tomorrow, 06:20
Joined
Aug 29, 2020
Messages
396
use Late binding as you did on your previous post.
add error handler to your function so you will not get runtime error, eg:


...
...
Dim AcroPDDocNew As Object
On Error Goto Err_Handler:
Set AcroPDDocNew = CreateObject("Acrobat.Application")
..
..
Graceful_Exit:
Exit Function

Err_Handler:
Msgbox Err.Number & vbCrLf & Err.Description
Resume Graceful_Exit
End Function

@arnelgp Thanks for your time. But I'm confused.
As I explained above, Acccess tells me I can not create an object with an activeX. Even if I use the error handler you explained, the following code won't run. Because the object is not created. The rest of the code depends on the object.

I'm away from my PC and I didn't test. But I have a feeling your method won't work. Anyhow, I will give it a try as soon as I'm back to school. (5 hours from now)

thanks again.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 05:20
Joined
May 7, 2009
Messages
19,229
remove the Adobe from VBA->Reference.
therefore, you will not get missing reference.

then use late binding With Error handler.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 22:20
Joined
Sep 12, 2006
Messages
15,641
I was going to suggest the same as @arnelgp. You need error handling here. Test it on your own machine. Just try to instantiate a non-existent object, and see what happens.

Set AcroPDDocNew = CreateObject("NoApp.Application")

Note that you also can't use any constants from the acrobat application. You have to replace everything with hardcoded values.
You can take out the reference, and see what compilation errors you get.
 

Isaac

Lifelong Learner
Local time
Today, 14:20
Joined
Mar 14, 2017
Messages
8,777
Whenever you figure out the correct objects to create late-bound, I highly doubt it will be "Acrobat.Application".

The application instance might be something like CreateObject("AcroExch.App")
 

Sun_Force

Active member
Local time
Tomorrow, 06:20
Joined
Aug 29, 2020
Messages
396
Whenever you figure out the correct objects to create late-bound, I highly doubt it will be "Acrobat.Application".

The application instance might be something like CreateObject("AcroExch.App")

I think you're on the right path. But unfortunately AcroExch.App was not the one. I'm still searching to find out how to late bind acrobat.

I really appreciate your time for trying to help.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 14:20
Joined
Oct 29, 2018
Messages
21,454
Hi. Pardon me for jumping in, but I have a couple of Acrobat demoes on my website, and I believe they're both using late binding. Maybe you could take a look to see if it might help you with your project. Just a thought...
 

Sun_Force

Active member
Local time
Tomorrow, 06:20
Joined
Aug 29, 2020
Messages
396
Hi. Pardon me for jumping in, but I have a couple of Acrobat demoes on my website, and I believe they're both using late binding. Maybe you could take a look to see if it might help you with your project. Just a thought...

I'm glad you jumped in and appreciate your offer. I'm just downloading and trying to see if it works for me. Will be back as soon as my tests are over.

Million thanks again.

Edit: Just a word before starting my test. I'm sure you know there's two reference for adobe. The Reader(free) version and the Pro. They behave completely different. Hope you have tested them on pro version.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 05:20
Joined
May 7, 2009
Messages
19,229
why not use Internet explorer object:
Code:
Private Sub tttt()
Const READYSTATE_COMPLETE = 4
Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")
With ie
    .navigate "file://D:\Downloads\P0502.pdf"
    Do While .Busy = True Or .ReadyState <> READYSTATE_COMPLETE 'Equivalent = .ReadyState <> 4
        DoEvents
    Loop
    .Visible = True
End With

End Sub
 

Sun_Force

Active member
Local time
Tomorrow, 06:20
Joined
Aug 29, 2020
Messages
396
why not use Internet explorer object:
Code:
Private Sub tttt()
Const READYSTATE_COMPLETE = 4
Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")
With ie
    .navigate "file://D:\Downloads\P0502.pdf"
    Do While .Busy = True Or .ReadyState <> READYSTATE_COMPLETE 'Equivalent = .ReadyState <> 4
        DoEvents
    Loop
    .Visible = True
End With

End Sub

@arnelgp I don't know what your code is supposed to do. But I'm sure internet explorer can not manipulate pdf files. IE is a tool to view them and can not add/remove/delete pages from an existing file.

Anyhow I tried your code and received the following on Do While line


2021-01-28_11-53-24.jpg



I'm on Microsoft Office 365 and Windows 10 if it matters.


thanks again.
 

Users who are viewing this thread

Top Bottom