473,791 Members | 2,881 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Applicat ion
Dim allMacro As String = "ALL-Macros"
myAccess.DoCmd. RunMacro(allMac ro)

I get the error.

"An unhandled exception of type 'System.NullRef erenceException '
occurred in
WindowsApplicat ion1.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 4684

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

Dim myAccess As Access.Applicat ion
Dim allMacro As String = "ALL-Macros"
myAccess.DoCmd. RunMacro(allMac ro)

I get the error.

"An unhandled exception of type 'System.NullRef erenceException '
occurred in
WindowsApplicat ion1.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.Applicati on (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("A ccess.Applicati on")

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

"An unhandled exception of type
'System.Runtime .InteropService s.COMException' occurred in
WindowsApplicat ion1.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.Applicat ion
Dim allMacro As String = "ALL-Macros"

myAccess = CreateObject("A ccess.Applicati on")
myAccess.Visibl e = True
myAccess.OpenAc cessProject("c: \data\idCard.md b")
myAccess.DoCmd. RunMacro(allMac ro)

the error is

"An unhandled exception of type
'System.Runtime .InteropService s.COMException' occurred in
WindowsApplicat ion1.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 "createObje ct" 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.goo glegroups.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 "createObje ct" 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.goo glegroups.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***********@g mail.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
3483
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 a Macro to copy that data to the campaigning table, give a numeric identifier to that record, and then delete all records with that identifier (in the 2nd table). This will keep the ASP > Access table clean. The campaigning software allows for...
7
8179
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 that situation is coming up for me shortly. Question: When you run the front-end on the Server, does Citrix clone the front end application database file for each user that connects or do they all connect to physically the same front-end...
0
2088
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 converted Access macro can do the same thing as the Excel macro does when i open the Excel file. Can anybody give me a hint? Thanks in advance! Alex
0
4875
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 = @"c:\ttt\Reports.mdb"; app.DoCmd.RunMacro(("Macro1" as Object), (1 as Object), (true as Object));
1
2667
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 the database and i am calling that function in AccessMacro, and if i run that access macro in the backend, itsworking fine.But when i tried to call that access macro fromVB.NET code,i'm not getting any errors, but that macro is notworking. I'm calling...
1
2174
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 database using the OpenDatabase function, but it then prompts me for which query, table, or form I want opened. Do I need to even open the database in this manner 1st? I just want to run my specified macro from within the Access db. Any suggestions?
1
2401
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 Office\OFFICE11\MSACCESS.EXE" "D:\Formatting Script.mdb" /x "Schedule_Macro" The macro is scheduled and ran fine when I used my User Id in the Schedule Task.
1
3454
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 the database will remain open. Instead I would like to close the whole database after it completes the macro processes. Here's how the current macro is tied with the task scheduler and I've
5
2135
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
1861
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 : Microsoft Access 12.0 Object Library Dim strDB As String Dim A As Object Application.ScreenUpdating = False
0
10426
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10154
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9993
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9029
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7537
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5430
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3713
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2913
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.