?
Solved

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

Posted on 2010-08-16
15
Medium Priority
?
1,255 Views
Last Modified: 2012-08-14
I need to run a macro in an access database on a server from vb.,net.

The following code works if the macro is in a local database.  If it is on the server.I get: Microsoft Office Access can't open the database because it is missing, or opened exclusively by another user.

What do I need to do to get this to run the macro from the mdb on the server?
RunPickAccessMacro("test")
Private Sub RunPickAccessMacro(ByVal sMacro As String)
        Dim oAccess As Object
        Try
            oAccess = CreateObject("Access.Application")
            oAccess.OpenCurrentDatabase "c:\test.mdb")
            oAccess.DoCmd.RunMAcro(sMacro)
            oAccess.Visible = False
        Catch e As Exception
            sErrNo = Err.Number.ToString
            sError = "RunPickAccessMacro " & vbCrLf & Err.Description & " " & "ErrNo: " & sErrNo
            dispError(sError)
        Finally
            oAccess = Nothing
        End Try
    End Sub

Open in new window

0
Comment
Question by:Delta7428
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 7
15 Comments
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33447942
Did use a connection string to connect with your database?
0
 

Author Comment

by:Delta7428
ID: 33447958
no connection string
0
 

Author Comment

by:Delta7428
ID: 33447986
Here is what I am using:
Private Sub RunPickAccessMacro(ByVal sMacro As String)
        Dim oAccess As Object
        Try
            oAccess = CreateObject("Access.Application")
            oAccess.OpenCurrentDatabase("\\mwwnas1\mwwnas1f\mis\Projects_Prod\PickTick\pickticket97_test.mdb;)"
            oAccess.DoCmd.RunMAcro(sMacro)
            oAccess.Visible = False
        Catch e As Exception

            sErrNo = Err.Number.ToString
            sError = "RunPickAccessMacro " & vbCrLf & Err.Description & " " & "ErrNo: " & sErrNo
            dispError(sError)
        Finally

            oAccess = Nothing
        End Try
    End Sub

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33447999
"Yes you can open/read/write to an acces db when it is opened by another user (access is a multiuser DB),  However you can NOT when it is opened exclusively by another user...you may also want to make sure that you have access permission to that remote directory!"
just take a look
http://social.msdn.microsoft.com/forums/en-US/adodotnetdataproviders/thread/31f75deb-ed3f-40e8-8084-ce51343b05cf

Dim sDBPassword as String        
Dim oDBEngine As DAO.DBEngine
Dim oDB As DAO.Database
        
sDBPassword = "Mypassword" 'database password 
oDBEngine = oAccess.DBEngine
oDB = oDBEngine.OpenDatabase(Name:=sDBPath, _
   Options:=False, _
   ReadOnly:=False, _
   Connect:=";PWD=" & sDBPassword)
oAccess.OpenCurrentDatabase(filepath:=sDBPath, _
   Exclusive:=False)
oDB.Close()
System.Runtime.InteropServices.Marshal.ReleaseComObject(oDB)
oDB = Nothing
System.Runtime.InteropServices.Marshal.ReleaseComObject(oDBEngine)
oDBEngine = Nothing

Open in new window

0
 
LVL 18

Accepted Solution

by:
John (Yiannis) Toutountzoglou earned 2000 total points
ID: 33448090
Adjust this code to your needs
Dim oAccess As Access.ApplicationClass

        'Start Access and open the database.
        oAccess = CreateObject("Access.Application")
        oAccess.Visible = True
        oAccess.OpenCurrentDatabase("\\mwwnas1\mwwnas1f\mis\Projects_Prod\PickTick\pickticket97_test.mdb", False)

        'Run the macros.
        oAccess.Run ("sMacro)
       

        'Clean-up: Quit Access without saving changes to the database.
        oAccess.DoCmd().Quit (Access.AcQuitOption.acQuitSaveNone)
        System.Runtime.InteropServices.Marshal.ReleaseComObject (oAccess)
        oAccess = Nothing

Open in new window

0
 

Author Comment

by:Delta7428
ID: 33448188
I am getting: Microsoft Office Access can't find the procedure 'ExportSelectedToDBF.' ErrNo: 2517

I tried to convert the macro to a module and I get message I do not have exclusive rights to the database.
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        Dim oAccess As Access.ApplicationClass
        Dim sMacro As String

        sMacro = "ExportSelectedToDBF"

        Try
            'Start Access and open the database.
            oAccess = CreateObject("Access.Application")
            oAccess.Visible = True
            oAccess.OpenCurrentDatabase("\\mwwnas1\mwwnas1f\mis\Projects_Prod\PickTick\pickticket97_test.mdb", False)

            'Run the macros.
            oAccess.Run(sMacro)


            'Clean-up: Quit Access without saving changes to the database.
            oAccess.DoCmd().Quit(Access.AcQuitOption.acQuitSaveNone)
            System.Runtime.InteropServices.Marshal.ReleaseComObject(oAccess)
            oAccess = Nothing


        Catch ex As Exception
            sErrNo = Err.Number.ToString
            sError = "**Macro" & vbCrLf & Err.Description & " " & "ErrNo: " & sErrNo
            dispError(sError)
        End Try
    End Sub

Open in new window

0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33448216
press Ctrl Alt del just to see if MSACCESS.EXE is already running...
Close anything that has relation with access...
maybe your access programm is already open...and you do not have exlusive access
0
 

Author Comment

by:Delta7428
ID: 33448307
I have checked many times to see if access is running when I get this.  ctrl alt del ... ctrl alt del.

I made a copy of the the mdb and tried modifying the macro again.  There was no lock on it and it let me modify the macro.  As soon as I run it, the lock icon appears beside the mdb name in explorer.  It's like the server puts a lock on it or something.
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33448349
try directly to use this in a button click
Dim oAccess As New Access.Application 'Access.Application
        oAccess.OpenCurrentDatabase ("\\mwwnas1\mwwnas1f\mis\Projects_Prod\PickTick\pickticket97_test.mdb", False)
        oAccess.DoCmd.RunMacro ("YOurMAcro name")
   
0
 

Author Comment

by:Delta7428
ID: 33448358
I changed the default open mode to open Exclusive.  It has worked several times in a row now, with both the original db and the copy I made.

Maybe just coincidence.  I have tried that before, changing it back and forth and it didn't help.  Maybe your code made the difference.

I am going to test some more..
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33448403
you try also this code applied in http://www.experts-exchange.com/Programming/Languages/.NET/Q_20956660.html

Private Sub RunMacro(ByVal sMacro As String)
        Dim oAccess As Object

        oAccess = CreateObject("Access.Application")
        ' Open the database
        oAccess.OpenCurrentDatabase(fsDBName)
        Try
            oAccess.DoCmd.RunMAcro(sMacro)
            oAccess.DoCmd.Maximize()
            oAccess.Visible = True
        Catch e As Exception
            MsgBox("Macro is cancelled or does not exist")
        Finally
            oAccess = Nothing
        End Try
    End Sub

Open in new window

0
 

Author Comment

by:Delta7428
ID: 33448478
I get the original error with that code.  That was where I started.

It seems to be working now.  But I was mistaken ... it is still showing a lock on the origial mdb in explorer, but not the copy and it will not let me modify my macro.  Do you know why that is?
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33448527
i know just that the error ...
and tha t you may have exlusive access...if the application is open exclusivelly you have read only access.
just check the path ..and adjust the code...
it is working on me perfect...
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33448542
did you try
oAccess.Run ("sMacro)
istead of oAccess.DoCmd.RunMacro
0
 

Author Comment

by:Delta7428
ID: 33448576
They both work.  The code below is working.  I'm just trying to figure out why the lock is there and I can't change the macro.  I converted the macro to a module on the copy of the mdb and it works either way I call it.

The copy of the mdb that I made does not have the lock icon by it in explorer.  The original does.  I cannot change the macro or create a module on the original mde or change it to open in shared mode.
Dim oAccess As Access.ApplicationClass
        Dim sMacro As String

        sMacro = "ExportSelectedToDBF"

        Try
            'Start Access and open the database.
            oAccess = CreateObject("Access.Application")
            oAccess.Visible = True
            oAccess.OpenCurrentDatabase("\\mwwnas1\mwwnas1f\mis\Projects_Prod\PickTick\pickticket97_test.mdb", False)

            'Run the macros.
            'oAccess.Run(sMacro)

            oAccess.DoCmd.RunMacro(sMacro)



            'Clean-up: Quit Access without saving changes to the database.
            oAccess.DoCmd().Quit(Access.AcQuitOption.acQuitSaveNone)
            System.Runtime.InteropServices.Marshal.ReleaseComObject(oAccess)
            oAccess = Nothing


        Catch ex As Exception
            sErrNo = Err.Number.ToString
            sError = "**Macro" & vbCrLf & Err.Description & " " & "ErrNo: " & sErrNo
            dispError(sError)
        End Try
    End Sub

Open in new window

0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question