• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 264
  • Last Modified:

ACCESS - Lock tables against all except my procedure

I have a bulk update procedure that runs fine when no one else is editing any records.  But, if a record is being edited, my update query just skips it.

Is there any way to lock the table(s) before running my procedure while still allowing it (and only it) to modify the records?

I am not using MS Access security, so everyone is logged in as Admin.

Thanks for your help.

-KP
0
Kaprice
Asked:
Kaprice
  • 4
  • 2
  • 2
  • +1
1 Solution
 
acampomaCommented:
You can open a table with exclusive rights and that will lock everyone out
0
 
mlpk_tyrCommented:
there are different levels of locks available for a database. So you can go for a table level locks or else you can put the update statements inside a transaction so that even if any update fails all the transaction are rolled back. By this method you may have to rerun the procedure even if 1 among 1000 update fails. you can rely on anyone of the methods based on your time and processing environment.

all the best,
mlpk_tyr
0
 
KapriceAuthor Commented:
My procedure is running an UPDATE QUERY.  So, if I open the table wtih exclusive rights, my query won't be able to modify it, either, right?  So, how can I lock the table while still being able to run my update query?
0
Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

 
mlpk_tyrCommented:
i cant follow your statement. but acquire the lock for update operation. as there are differnt locking modes available . So if you acquire a lock that would satisy the need then it will surely do,

all the best,
mlpk_tyr
0
 
fulscherCommented:
Kaprice

This is an interesting problem: In Access, users by default do NOT lock a table at all when editing it; a lock is set very briefly when the record is updated. (in the forms designer, "No Lock" in the table / Record Locks property).

This means that if some of your users are currently editing the record, you run your query, and users save their records, the table will be overwritten with the old values.

You can protect yourself against this by using "pessimistic locking" (in the forms designer, use "current record" or "all records". "All records" should be used only if users are editing in the "Single Form" view; if they're working in the "continous form" or "datasheet" view, all visible records will be locked. So, if users are working in the continuous or datasheet view, they are likely to lock themselves out if you use "all records" locking.

Also, Access does not lock individual records, but pages; for small records, a lock could cover more than one record.

So, it really depends a bit on your situation; you'll have to experiment.

You can modify your query to use pessimistic locking (open the query, use Edit/Properties, and set the query "Record Locks" to "All Records").

Hope this helps
Jan
0
 
KapriceAuthor Commented:
Access 2000 has the option of record locking instead of page locking.  And, I've confirmed that if a user is in a table and the pencil is showing, it's in EDIT mode, and an update query will fail on that record.

What I'm not clear on is, if I LOCK a table, how am I able to modify it?  It's locked now?  IOW, I need it locked against everyone else but available to my query.
0
 
fulscherCommented:
Kaprice,

"Locking" means it is locked against access of anybody EXCEPT your current transaction. In other words: If your transaction locks the table, you can access it, but nobody else. Usually, you would set the lock, run the procedure, remove the lock to make sure that everything is consistent.

Remember that the lock works on a transaction level. If you lock the table using VBA first and then try to run an SQL procedure against it, that's TWO transactions, so the VBA code will win and the SQL procedure will fail.

Hope this helps
Jan
0
 
KapriceAuthor Commented:
OK, so here's a scenario:

In VBA...

Sub Sample
...
...
...
Lock the table
Run an Update Query
Unlock the table
...
...
...
End Sub

That won't work, right?  Because the VBA code locked the table so the Query can't access it, right?

So, what's the solution in this example?
0
 
KapriceAuthor Commented:
Well, I do't have the right answer (though a few hints in the right directioni), here, but Fulscher made the most attempts, so I'll award the points there.

Here's the answer I found on my own:

Apparently, when you execute a query with VBA, there's a parameter for desired lock type.  I can use that parameter to lock the recordset against everyone/everything while allowing the query to run through that code.

Thanks all for your efforts.

-Keith Price
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now