473,387 Members | 1,532 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Running an Access macro from a VB.NETprogram

I am trying to run a macro from my VB.NET program. Here is my code.

Dim myAccess As Access.Application
Dim allMacro As String = "ALL-Macros"
myAccess.DoCmd.RunMacro(allMacro)

I get the error.

"An unhandled exception of type 'System.NullReferenceException'
occurred in
WindowsApplication1.exe

Additional information: Object reference not set to an instance of an
object."

I am new to running other programs through a program of my own and am
not sure what I am doing wrong. Any help or pointers on the subject are
welcome!

Thanks!

Oct 6 '06 #1
8 4628

Sh***********@gmail.com wrote:
I am trying to run a macro from my VB.NET program. Here is my code.

Dim myAccess As Access.Application
Dim allMacro As String = "ALL-Macros"
myAccess.DoCmd.RunMacro(allMacro)

I get the error.

"An unhandled exception of type 'System.NullReferenceException'
occurred in
WindowsApplication1.exe

Additional information: Object reference not set to an instance of an
object."
I think you will need to do a CreateObject call for the myAccess
object.

Do a search of this newsgroup for Excel.Application (which undoubtedly
works in a similar fasion) for some insight.
>
I am new to running other programs through a program of my own and am
not sure what I am doing wrong. Any help or pointers on the subject are
welcome!

Thanks!
Oct 6 '06 #2
I tried adding

myAccess = CreateObject("Access.Application")

just before my DoCmd.RunMacro command and now I am recieving the error
message

"An unhandled exception of type
'System.Runtime.InteropServices.COMException' occurred in
WindowsApplication1.exe

Additional information: You can't carry out this action at the present
time."

do i need to start somthing else before i can call this?

Oct 6 '06 #3
I added some more and am getting a strange error.

Dim myAccess As Access.Application
Dim allMacro As String = "ALL-Macros"

myAccess = CreateObject("Access.Application")
myAccess.Visible = True
myAccess.OpenAccessProject("c:\data\idCard.mdb")
myAccess.DoCmd.RunMacro(allMacro)

the error is

"An unhandled exception of type
'System.Runtime.InteropServices.COMException' occurred in
WindowsApplication1.exe

Additional information: Microsoft Office Access can't open the database
because it is missing, or opened exclusively by another user."

I know my path is correct, not very sure how to proceed.

thanks again

Oct 6 '06 #4
Dear Shooter4Life8,
Additional information: Microsoft Office Access can't open the database
because it is missing, or opened exclusively by another user."
If you use Access with that database at the same time it might be, that
Access opened it exclusively. In this case, you would have to close
Access first before your program can open the database.

If this is not the case, check if there is an LDB file (when neither
Access nor your program is running. If that is the case, delete it and
try again.

Best Regards,

HKSHK
Oct 6 '06 #5
I have tried closing all instances of the Access program before I run
my program. My program opens Access to try to do this.. Could that be
part of the problem?
Not sure what an LDB file file is.

HKSHK wrote:
Dear Shooter4Life8,
Additional information: Microsoft Office Access can't open the database
because it is missing, or opened exclusively by another user."

If you use Access with that database at the same time it might be, that
Access opened it exclusively. In this case, you would have to close
Access first before your program can open the database.

If this is not the case, check if there is an LDB file (when neither
Access nor your program is running. If that is the case, delete it and
try again.

Best Regards,

HKSHK
Oct 6 '06 #6
An ldb file is an Access locking file (located in the same folder as your
mdb, mde or mdw)... You will only see it if someone (or yourself) has the
database open (even if via linked tables etc.). If your Access mdb is
secured using Workgroup security you will also have to reference the
appropriate mdw (i.e. workgroup file) to open it.

I'm not sure if an ldb would be created against the original file if you use
createOnject. I have never had to do this myslef.

You could also try opening the ldb in notepad (you may have to wrap the
text) and you will see the machine and user name for anyone accessing the
mdb. You could possibly be in there twice. Note that the ldb sometimes still
shows users that have logged out already (though I don't think this would
cause you a problem).

Try:
a) Before running your code, check if there is an ldb accompanying your mdb
(i.e. in the same folder), if there is then someone has the mdb open (or the
ldb hasn't been cleared so just delete it, or you have a process running
thats still accessing it).

b) Run to the error, without clicking 'OK' navigate to wherever the mdb is
and check for an ldb, if there is one present now that wasn't before, have a
look inside and see who's logged in (you may be in there more than once.)

c) Click OK, see if it still exists after passing the error.

This is not a solution, but may help you pin down the problem...

Also (and I may be talking complete rubbish here), open up Acces, go to
options and see if it is set to open mdb's exclusively by default. I'm not
sure if this would affect "createObject" but if it did then it may be worth
deselecting the option and trying again.

Note: If all you are doing is manipulating data then you'd be better off
just migrating the macro into vb...

hth Mark

<Sh***********@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
>I have tried closing all instances of the Access program before I run
my program. My program opens Access to try to do this.. Could that be
part of the problem?
Not sure what an LDB file file is.

HKSHK wrote:
>Dear Shooter4Life8,
Additional information: Microsoft Office Access can't open the database
because it is missing, or opened exclusively by another user."

If you use Access with that database at the same time it might be, that
Access opened it exclusively. In this case, you would have to close
Access first before your program can open the database.

If this is not the case, check if there is an LDB file (when neither
Access nor your program is running. If that is the case, delete it and
try again.

Best Regards,

HKSHK

Oct 7 '06 #7
The LDB file gets created when I open the file just as you said and
goes away when I close it so I am the only one accessing the database.
When I start access and try to open the file however, it does not
create a ldb file. In fact, the database I try to open (along with the
ldb file) never gets opened before during or after the error.

I also checked the options and the default open mode was shared instead
of exclusive (which doesnt make much sense with the error message im
getting).

Migrating the macro into vb? I looked at the macro to see what it is
doing but am unsure how to implement it into VB... I am very new to
this sort of programming and learning a lot as I go, thanks for all the
help I really appreciate it.

Mark wrote:
An ldb file is an Access locking file (located in the same folder as your
mdb, mde or mdw)... You will only see it if someone (or yourself) has the
database open (even if via linked tables etc.). If your Access mdb is
secured using Workgroup security you will also have to reference the
appropriate mdw (i.e. workgroup file) to open it.

I'm not sure if an ldb would be created against the original file if you use
createOnject. I have never had to do this myslef.

You could also try opening the ldb in notepad (you may have to wrap the
text) and you will see the machine and user name for anyone accessing the
mdb. You could possibly be in there twice. Note that the ldb sometimes still
shows users that have logged out already (though I don't think this would
cause you a problem).

Try:
a) Before running your code, check if there is an ldb accompanying your mdb
(i.e. in the same folder), if there is then someone has the mdb open (or the
ldb hasn't been cleared so just delete it, or you have a process running
thats still accessing it).

b) Run to the error, without clicking 'OK' navigate to wherever the mdb is
and check for an ldb, if there is one present now that wasn't before, have a
look inside and see who's logged in (you may be in there more than once.)

c) Click OK, see if it still exists after passing the error.

This is not a solution, but may help you pin down the problem...

Also (and I may be talking complete rubbish here), open up Acces, go to
options and see if it is set to open mdb's exclusively by default. I'm not
sure if this would affect "createObject" but if it did then it may be worth
deselecting the option and trying again.

Note: If all you are doing is manipulating data then you'd be better off
just migrating the macro into vb...

hth Mark

<Sh***********@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
I have tried closing all instances of the Access program before I run
my program. My program opens Access to try to do this.. Could that be
part of the problem?
Not sure what an LDB file file is.

HKSHK wrote:
Dear Shooter4Life8,

Additional information: Microsoft Office Access can't open the database
because it is missing, or opened exclusively by another user."

If you use Access with that database at the same time it might be, that
Access opened it exclusively. In this case, you would have to close
Access first before your program can open the database.

If this is not the case, check if there is an LDB file (when neither
Access nor your program is running. If that is the case, delete it and
try again.

Best Regards,

HKSHK
Oct 9 '06 #8
On 9 Oct 2006 07:53:18 -0700, Sh***********@gmail.com wrote:

¤ The LDB file gets created when I open the file just as you said and
¤ goes away when I close it so I am the only one accessing the database.
¤ When I start access and try to open the file however, it does not
¤ create a ldb file. In fact, the database I try to open (along with the
¤ ldb file) never gets opened before during or after the error.
¤
¤ I also checked the options and the default open mode was shared instead
¤ of exclusive (which doesnt make much sense with the error message im
¤ getting).
¤
¤ Migrating the macro into vb? I looked at the macro to see what it is
¤ doing but am unsure how to implement it into VB... I am very new to
¤ this sort of programming and learning a lot as I go, thanks for all the
¤ help I really appreciate it.
¤

Is the read-only attribute set on the database file by any chance? Is the database located on a
network resource?
Paul
~~~~
Microsoft MVP (Visual Basic)
Oct 9 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jason L. | last post by:
Here's the scenario. Using a campaigning applicaion for an eNewsletter. It writes to an Access table. I have an ASP web page that writes to another table. I chained 3 Access queries together into...
7
by: Rob | last post by:
I am an Access developer and have done many Access databases in the standard Front-end on the workstations, backend on the server (over a LAN) but have never worked with Access over Citrix, though...
0
by: Alex | last post by:
i have a module in Access which opens an existing Excel file and envokes a macro within the Excel file to draw graphs. now i am trying to convert the Excel macro to an Access one so that the...
0
by: Evgeny | last post by:
I'm trying to run an Access Macro from .NET. My code right now looks like this: Access.ApplicationClass oAccess = new Access.ApplicationClass(); oAccess.Visible = true; string path =...
1
by: Sen K via .NET 247 | last post by:
(Type your message here) Hi, Any help is appreciated. I have a situation wherein i need to compact access db after somebusiness logic through VB.NET.I've written a function in VBA tocompact...
1
by: jbird27 | last post by:
I am an extreme newbie on VB, so I apologize if this seems so simple. I am trying to run a module from an Excel spreadsheet that will open and run an Access macro. I have been able to open the...
1
by: yello | last post by:
Hi All, I have a MS Access macro which needs to be scheduled in the Task Scheduler. I am using the following link to schedule the macro "C:\Program Files\Microsoft...
1
by: skennd | last post by:
Hello, All your help is appreciated in this problem. I am running a macro to execute certain queries and the macro is started to run by a windows task scheduler. However, after the macro runs...
5
by: redman08 | last post by:
Is there a way of producing a printout of an Access macro (or all macros in the database) using VBA, ideally one line per command for documentation purposes? Many thanks for any help.
1
by: zwheeler | last post by:
I am trying to run an access macro from an excel application. i found the following code and tried to implement it but i keep getting a error 2046: i go to references and set the references to :...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.