I am getting a write conflict error on one of my forms. I think I know the reason why, I just don't know how to fix it.
On my main form, I do a "Select * FROM TableName" query...
There is a checkbox on my form. It is unbound, but looks at a text field in the table. I use the text field for permissions. The checkbox is used to "lock" a textfield from edition. What happens is, on the form, the user checks the checkbox to lock the textfield. Then, in VBA code, i execute an Update query which updates a text field with the username environmental variable. This way, the user that locked the text field is the only user that can unlock it. All other users get a message when trying to unlock it, alerting them that username has it locked, and to contact them. This is managed by checking for the existance of a username in the table's text field. If one is set, then the checkbox is checked and the textbox.Locked is set to true.
In the AfterUpdate of the checkbox, here is the code:
Private Sub chkDescriptionLock_AfterUp
date()
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
Dim lockingUser As String
'Get connection to database
Set dbs = CurrentDb()
If Me.chkDescriptionLock Then
'Box is checked
txtPartitionDescription.Lo
cked = True
'Build SQL query
strSQL = "UPDATE Partition Set Partition.Description_Lock
edBy = '" & GetUserName() & "' where Partition.Pk_Partition = " & [PK_Partition] & ";"
dbs.Execute (strSQL)
MsgBox "You have now locked the description from editing. Only you can now remove the lock"
Else
'Box is Unchecked
strSQL = "SELECT Partition.Description_Lock
edBy from Partition WHERE Partition.PK_Partition = " & [PK_Partition] & ";"
Set rst = dbs.OpenRecordset(strSQL)
lockingUser = rst.Fields("Description_Lo
ckedBy")
If lockingUser = GetUserName() Then
'Build SQL query
strSQL = "UPDATE Partition Set Partition.Description_Lock
edBy = '' where Partition.Pk_Partition = " & [PK_Partition] & ";"
dbs.Execute (strSQL)
txtPartitionDescription.Lo
cked = False
MsgBox "Description field successfully unlocked!"
Else
Me.chkDescriptionLock.valu
e = 1
MsgBox "Description field is locked by " & lockingUser & "." & vbCrLf & "You will need to contact this user to unlock it"
End If
End If
End Sub
As you can see, its pretty straight forward.
I think I'm getting the Write Conflict Error because I am using an Update query in VBA to change the value in the database, while form never gets updated to reflect this. How do a pull in the new changes into my form, and do so without screwing up how my form is filtered? (see how it is filtered below:)
Private Sub SyncFormToCombobox()
'-------------------------
----------
---
'SyncFormToListbox()
'This function syncronizes the forms
'recordset to the the listbox browser
'-------------------------
----------
----
'lets syncronize the form's recordset
Set rs = Me.RecordsetClone
rs.FindFirst "[PK_Partition] =" & Str(Nz(Me![cmbBrowse], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
DescriptionLock
End Sub
thanks for any help I can get...
Start Free Trial