views:

76

answers:

3

Hi guys, So I've developed this Access 2007 application with about 2 forms, a lot of VBA code and a bunch of tables.

Now the business wants to run this off a network drive (call it G:\ for example). My current solution (which I've already implemented is have a table similar to:

__________________
|Setting | Value |
==================
Updating    1
UpdateBy   User1

So let me give you a context. When the application runs there is a button called "update" which updates the local table from a remote server so we can apply filtering. Now when two people (user1, user2) launch the application, and one person clicks update then the updating field is set to true, and the updateby is set to their name. So User number 2 tries to update, it checks if the updating field is true, if it is then it gives them a message (to user two, not to user one).

It works beautifully right now, but here is the problem: Lets say user1 is updating, and closes his program (or taskkills it) or the power disrupts, then the application shuts off with the updating field set to to true. Now no matter who launches it, they can not update because its "already updating"

Can you guys think of a solution to this? Maybe a workaround?

+2  A: 

Please do not run an Access application with more than one user when you have not split the database. It will cause endless trouble. The data portion (back-end) should be put on the server and the code and forms (front-end) should be put on each users desktop.

More information: http://support.microsoft.com/kb/162522

Remou
I don't know how I can accomplish this with Access? So your saying it's a better solution to let the end user copy the access file to the local computer and then run it?
masfenix
I dont think this is what I am looking for. Because the problem still exists even if I do split the database. Once the table is set to `updating = true` and the update process is distrubed (ie, it dosnt finish) then the field stays true. and no one else can update
masfenix
I am saying that unless you split the database you will end up with corrupt data. I do not see the advantage of your set-up.
Remou
well the data is in one table, and the table deletes itself and "updates" with fresh values often. I did bring this up with the business and they said it is too complicated (its a world wide company) and the split db might get lost or deleted so they dont want to go that route.
masfenix
Hey so if i split the database, and my FE opens up the recordset and locks it (look at HansUp's comment), then it will lock it in the BE right? its not like the FE creates a local temp copy right?
masfenix
It all depends on how you get the data. Why do you wish to lock out one user? Access supports updating by a number of users and locks the record being edited itself when it is used properly.
Remou
Yes, opening the recordset from the FE will lock the table in the BE. You owe it to yourself to follow Remou's advice about splitting. I don't really understand why "might get lost or deleted" applies to a split Db, but not to a single Db which all users open directly.
HansUp
With linked tables, the usual and most convenient way of getting the data, record level locking is standard, not locking the whole recordset.
Remou
Hey thanks, so is HansUP way record level locking? or locking the entire rs? What is the difference? sorry, I should really google this but I need to finish this project asap (as its cutting in to my time for another project). The amount of work they give to interns these days eh.
masfenix
It locks the whole table. The usual way is to bind a table or query to a form and allow each user to update records as required, this only locks the record being edited.
Remou
The method I suggest would place an exclusive lock on tblUpdateStatus. It locks the table, not just a record. In situations where you want to allow multiple users to change data in a table at the same time, record locking is appropriate. But, in your case, you **don't** want multiple users changing tblUpdateStatus at the same time.
HansUp
Oh, okay. so the way my `update` works is that the first statement is `delete * from local table`. Then I get the data from a remote server (I reference LotusScript) and loop through a `NotesCollection` and manually have `insert into localtable values(1, 2, 3)`
masfenix
In that case, you should be locking the table being updated.
Remou
+1  A: 

Consider a different locking strategy. In the click event of your "update" button, you can first open a recordset based on your tblUpdateStatus (the table where you've been writing UpdateBy) with dbDenyWrite + dbDenyRead options.

Set rst = db.OpenRecordset("tblUpdateStatus", _
             dbOpenTable, dbDenyWrite + dbDenyRead)

Then do your other operations for the "update" button. Afterward, close and release the recordset ... which releases the tblUpdateStatus lock.

Trap the error when a user is unable to open the recordset (because another user has the table locked), give them a message to try later and exit your click event subroutine.

With this approach, when user1 locks tblUpdateStatus but exits Access uncleanly, her lock on tblUpdateStatus is released. You may not even need to update tblUpdateStatus unless you want to record which user has it locked.

See Create and Use Flexible AutoNumber Fields (from the Access Cookbook) for more details about using a recordset with dbDenyWrite + dbDenyRead.

HansUp
Wow, thankyou. I am currently coding this in. And @Remou, thankyou. I think I will have to convince them to going that route.
masfenix
+2  A: 

Read my article on why you split here:

http://www.members.shaw.ca/AlbertKallal/Articles/split/index.htm

In the above, I don't just tell you to do this, but I tell you WHY you split.

It should help you a lot in terms of users tripping over each other.

Albert D. Kallal
holy crap, thats your article? haha i've already read it. You have some pretty high rankings on google for specific keywords.
masfenix