|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Running an Access macro from a VB.NETprogramDim 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! Shooter4Li***@gmail.com wrote:
Show quoteHide quote > I am trying to run a macro from my VB.NET program. Here is my code. I think you will need to do a CreateObject call for the myAccess> > 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." object. Do a search of this newsgroup for Excel.Application (which undoubtedly works in a similar fasion) for some insight. Show quoteHide quote > > 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! 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? 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 Dear Shooter4Life8,
> Additional information: Microsoft Office Access can't open the database If you use Access with that database at the same time it might be, that > because it is missing, or opened exclusively by another user." 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 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: Show quoteHide quote > 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 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 <Shooter4Li***@gmail.com> wrote in message Show quoteHide quote news:1160171382.087767.172770@m73g2000cwd.googlegroups.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 > 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: Show quoteHide quote > 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 > > <Shooter4Li***@gmail.com> wrote in message > news:1160171382.087767.172770@m73g2000cwd.googlegroups.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 > > On 9 Oct 2006 07:53:18 -0700, Shooter4Li***@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)
need help on optional arg
Overlapping controls creating pictureboxes on the fly Set Focus to textbox on tab control Redrawing on GDI+ How to determen the object ? WEB combobox won't fire event NullReferenceException with shared members Referencing parameters collection member by Name bombs? crash at closue msvbvm60.dll |
|||||||||||||||||||||||