sambo
Registered User.
- Local time
- Today, 15:35
- Joined
- Aug 29, 2002
- Messages
- 289
Problem..
I run an append query behind an OnClick Event. Works fine with one user. The problem arises when two users click the button at the exact same time. This creates a primary key infraction because the db tries to write to the table at the same time from both machines. After this string of events the database is corrupted and I have to repair it. BAAADDD!!!
So..
I added a little patch. I created a table (tblTimer) that simply stores the user name of most recent entrant into the form containing the button. Now when the person clicks the button I implement the following code..
This code is intended to make sure that only one user at time can add records to the table. If your entry fails, then I update the tblTimer.user to the current user name. This way, you are moved to the top of the Queue. Unfortunately, with the 1 second lag between network and front ends, if the buttons are clicked at exactly the same time, this method still fails.
Any suggestions..
I run an append query behind an OnClick Event. Works fine with one user. The problem arises when two users click the button at the exact same time. This creates a primary key infraction because the db tries to write to the table at the same time from both machines. After this string of events the database is corrupted and I have to repair it. BAAADDD!!!
So..
I added a little patch. I created a table (tblTimer) that simply stores the user name of most recent entrant into the form containing the button. Now when the person clicks the button I implement the following code..
Code:
If DLookup("[User]", "tblTimer", "[Func] = 'Add Data'") <> Me.User Then
MsgBox "WARNING!!" & vbCrLf & _
"No Entries Made" & vbCrLf & _
"You Clicked at the Same Time as Another User Please Try Again"
'reset the tblTimer.User to the Current User Name, give Record Locking Time to Queue
DoCmd.SetWarnings False
DoCmd.RunSQL "UPDATE tblTimer SET tblTimer.[User] = '" & _
Me.User & "' WHERE (((tblTimer.Func)='Add Data'));"
DoCmd.SetWarnings True
Exit Sub
Else
'Do the button stuff (append query)
This code is intended to make sure that only one user at time can add records to the table. If your entry fails, then I update the tblTimer.user to the current user name. This way, you are moved to the top of the Queue. Unfortunately, with the 1 second lag between network and front ends, if the buttons are clicked at exactly the same time, this method still fails.
Any suggestions..