Row Level Locking from Excel VBA query

B

belkingold

I'm trying to run a query from Excel VBA with SQL using Jet 4.0 to an
access database. There are multiple users accessing the database at
the same time, and I am trying to set up row level locking in the
query that I am using so that two users will not get the same order
that is waiting in queue. Here's the applicable code I'm using:

Dim dbsConn As ADODB.Connection
Set dbsConn = New ADODB.Connection
Dim myDBname As String

myDBname = "T:\SOC\LNP1\Call center errors\LNP Data Track Back End
Tables\LNP Data Track_be.mdb"
BCNPCNDate = Date - 7
LNPUserID = Range("AK1").Value


Dim connString As String
connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
myDBname & "; Jet OLEDB:Database Locking Mode = 1;User Id=" &
LNPUserID & "; Persist Security Info=false; Jet OLEDB:System
database=T:\SOC\LNP1\Call center errors\LNP Data Track Back End Tables
\LNP Data Track_be.mdw"

dbsConn.Open connString

Dim rs As Recordset
Dim strSELECT As String, strSELECT1 As String, strSELECT2 As
String
Dim rSELECT As String

Set rs = New ADODB.Recordset
rs.LockType = adLockPessimistic
rs.CursorType = adOpenDynamic

LNPSpecName = Range("AK1").Value


strSELECT5 = "SELECT TOP 1 * from [RES LNP Production
Table] [READCOMMITED, XLOCK, READPAST] WHERE [LNPSpecName] is NULL
ORDER BY [LSRSentDate];"
' New/Unassigned orders


rs.Open strSELECT5, dbsConn, , , adCmdTableDirect

If rs.EOF Then
rs.Close
'do nothing
Else

With rs
.Fields("LNPSpecName").Value = LNPSpecName
.Fields("LNPProcessDate").Value = Date
.Fields("LNPProcessTime").Value = Time
.Update
End With

MsgBox ("New Order")
OrderType = "New Order"

GoTo PullValuesIn
End If



Unfortunately, any time two users query the database for a new order
at about the same time, they receive the same record. Can anyone tell
me what I'm missing? Why isn't READPAST ignoring the locked records?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top