Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In VBA, cannot use Access.Application object

This does NOT work:

Sub X()
    Dim A As Access.Application
    Set A = CreateObject("Access.Application")
    'Do Stuff
End Sub

However, this DOES work:

Sub X()
    Dim A As Object
    Set A = CreateObject("Access.Application")
    'Do Stuff
End Sub

I know they do virtually the same thing, but can anyone tell me how to make an access.application object? I should add that I have Crystal Reports 11 and on my last upgrade, it may have 'unregistered' some VBA DLLs.

(Update 2009-06-29)

In response to the first 2 questions, I am using MS Access VBA to control some other Access & Excel files. Since this will only ever run on my local machine, I can guarantee that Access will always be installed. I have also referenced the "Microsoft Access 11.0 Object Library" (MSACC.OLB).

I know there's ways around this, i.e. use early binding when coding, and switch to late binding when running it, I just don't understand why the early binding method doesn't work at all on my machine (Of course, the code works fine on another machine with Access).

like image 515
PowerUser Avatar asked Aug 05 '26 16:08

PowerUser


2 Answers

If you are writing this in Access there is no need to do that as the Application object is already there for you. If you are writing this in Excel or Word then you need to add a reference to the Access Library. Go to Tools/References and look for Microsoft Access XX Object Library

like image 200
DJ. Avatar answered Aug 08 '26 12:08

DJ.


Hello,
The code that you say is not working is legal syntax. What error are you getting? When does it occur? Do you know the line of code it happens at?

Just as a side note, this is legal syntax as well:

    Dim accApp As Access.Application
    Set accApp = New Access.Application

But to be clear, the CreateObject Syntax is legal and not the source of the problem.

like image 40
Oorang Avatar answered Aug 08 '26 11:08

Oorang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!