473,396 Members | 2,147 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,396 software developers and data experts.

VBA: Can't save because I don't have exclusive access...

dsatino
393 256MB
Ok, this is an easy one that I've solved in the past but I just can't for the life of me remember how.

I've been asked to modify a front end and am working on a copy stored on my desk top so I know there's no one else using it.

Here's the issue: any time I run any code with any initialized object variable, I can't write any more code without shutting it down and starting it back up because it won't let me save any work because '[another user has the db open]'.

I'm setting all the object variables to Nothing, but that doesn't help so I know there's nothing lingering open.
Oct 22 '10 #1
7 2105
NeoPa
32,556 Expert Mod 16PB
I really don't know about this one. Let's try to find something :
  1. First look at the Locals Pane (View \ Locals Window from the IDE). Is there anything there that indicates anything is still maintained? Particularly a reference to the database?
  2. Next look at the stop project button that's available in the Standard toolbar. Does it allow you to save after clicking on that?

Not much I know, but see if either gives you anything.
Oct 22 '10 #2
dsatino
393 256MB
Nope, neither of those helped. Here's an update though.

I've traced this back to the .ldb file which has two occurrences of my machine as having the file open. Essentially, what's happening is that one occurrence is opened when I first open the file and the other occurrence is opened when I run the code.

I decided to start from the beginning of the code and add pieces on until I acheived this second lock in the .ldb.

Fortunately, that didn't take long at all. Here is the code that causes this:

Expand|Select|Wrap|Line Numbers
  1. Public Function CreateWrkJet()
  2. Set wrkjet = CreateWorkspace("Jet1", "Admin", "", dbUseJet)
  3. DBEngine.Workspaces.Append wrkjet
  4. End Function
For some quick background, this is code I use in basically every interface I build so it's time tested. All of the variables are declared globally in a seperate module.

Creating the new workspace doesn't cause the lock, but appending to the collection does.

What's odd is that I use this same snippet of code in dozens of other projects and have not had the same issue. I even opened those projects up and couldn't reproduce it. So I have the same exact code running in different projects with different actions being taken with respect to the .ldb file.

To further my problem is that any project I start (just test db's), I have this issue. I've taken all of the properties from the projects that it works fine with and set my new db to imitate those, but it's had no effect.

Now, I was able to get this to work by adding a line of code:

Expand|Select|Wrap|Line Numbers
  1. Public Function CreateWrkJet()
  2. Set wrkjet = DBEngine.Workspaces(0)
  3. Set wrkjet = CreateWorkspace("Jet1", "Admin", "", dbUseJet)
  4. DBEngine.Workspaces.Append wrkjet
  5. End Function
It seems that if I initialize the workspace variable in the default workspace first I don't have the issue. So it seems there is something I'm missing with respect to the DBEngine and how it handles locks, database properties, and sharing. Maybe more. Maybe less, I don't know.
Oct 25 '10 #3
dsatino
393 256MB
It just occurred to be that I was calling a function with no result. Why would I do that I wondered. It then occurred to me that the only reason I would write a function that doesn't return a result was to call it from the AutoExec macro.

This explained why this code worked on all my other projects and not this one.

I guess that by specifically referencing the Jet engine on open causes the user and the code to seen as one in the same (for lack of a better way of explaining it).
Oct 25 '10 #4
dsatino
393 256MB
So I put this in the AutoExec macro and I have no more issues:

Expand|Select|Wrap|Line Numbers
  1. Public Function WS0Ref()
  2. With DBEngine.Workspaces(0)
  3. End With
  4. End Function
  5.  
Oct 25 '10 #5
NeoPa
32,556 Expert Mod 16PB
It seems the original code may have been developed to give your code access to the database. I don't use similar code myself, but I'm guessing DBEngine.Workspaces(0) is already set, before you do anything to it even, to a working copy of the current database.

You may want to try accessing it without ever setting it first. As I say, I don't really know my way around this area, but I would expect that to work for you from what you've posted.

By the way, my first point in post #2 was an attempt to find just such a thing as this. An open database or workspace would be expected to lock the database from you. You found a better way of discovering it though. Well done.
Oct 25 '10 #6
dsatino
393 256MB
The code is all my own. Most of my interfaces hit various DB's and DB types so I use a lot of workspaces and hence a have a lot of canned code that I just use over and over.

This particular one (Jet1) is the one I use to refer to the current db. (There are various reasons I don't use the currentdb function).

In any case, DBEngine.Workspaces(0) is the default workspace of any Access DB and it can be accessed without setting it.

Apparently what happens, or my best interpretation of what happens, is that the JET DBEngine workspaces collection creates a user lock when it's first opened/referenced/loaded as if it's a user. So when you open the DB you create a .ldb. Now if you create a new workspace, a lock is created as well. So essentially your user and your code, although on the same machine are seen as seperate users.

Apparently, by referencing the the workspace collection during the load of the database, there is no distinction between the user and the code.

I have no idea if that makes sense, but it seems to be the case
Oct 26 '10 #7
NeoPa
32,556 Expert Mod 16PB
It sounds like we're saying quite similar things, just not in the same way. I'm pleased you have a solution anyway :-)
Oct 26 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Alan Jones | last post by:
Access 2000 onwards introduced a restriction that only allows you to edit and save forms, reports and macros when you have exclusive access to the database, i.e. no other user has the database...
3
by: Mads Petersen | last post by:
I'm stuck in this code. Hope you can and will help me. I launch it from excel. I have made the following code work, but not as i whant. I need the ranges to be working with something like xlDown....
1
by: JohnC | last post by:
I have this exact same scenario. It is new and seems to be related to when we installed Adobe 7.0 Standard/Professional. We have an MDB on a LAN file server. Using Access 2K and Windows 2K. ...
18
by: Andre Laplume via AccessMonster.com | last post by:
I have inherited a bunch of dbs which are are shared among a small group in my dept. We typically use the dbs to write queries to extract data, usually dumping it into Excel. Most dbs originated...
4
by: Luis | last post by:
Hi, I can a big problem... because I have a byte data = new byte, and I need to save this to a field on my MySQL database (here I have a BLOB field) but ¿can I save it? because if I put: Insert...
9
by: shades234 | last post by:
When i go to open my Access database from certain computers, i get multiple popup messages stating the same thing. They all say "You do not have exclusive access to the database at this time. If...
1
by: Mohsin | last post by:
Hi, any one can help me to save visual Basic Data in Access to link through Data control or ODBC. when i am trying to save vb data in Access after making link through data control it is not saving...
1
by: PW | last post by:
Hi, All of a sudden one of our clients can't use her application. She gets "You don't have exclusive access to your database at this time" when trying to open our application. The only thing...
2
by: Zippy | last post by:
I recently updated one of my clients from Access 97 front-end to Access 2003. (Database still in 97 format). They have about 5 networked PCs. On one of these PCs only, the user gets a warning...
3
by: Tom | last post by:
I can successfully do the following: xdocument doc = xdocument.load(... my file); xelement bla = doc.descendants.("it").first(); .... do stuff ... doc.save("myfile"); the above works great. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...
0
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,...

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.