Write Conflict in Code

C

Chris A.

I'm using the following code to update 2 fields in a table
with the current users information and the date:

Private Sub btnApprv1_Click()
Dim db As Database
Dim rs As Recordset
Dim currentuser As String
Dim strSQL As String

Set db = CurrentDb()

currentuser = Forms!frmLogin!txtUserName
Date = Now()
ID = Forms!PurchaseRequisition!PRID

strSQL = strSQL & "SELECT * FROM tblPR WHERE "
strSQL = strSQL & "PRID = " & Forms!
PurchaseRequisition!PRID

Set rs = db.OpenRecordset(strSQL)

DeptAppr = rs![DeptAppr]

If IsNull(DeptAppr) Then
rs.FindFirst "[PRID] = " & ID
rs.Edit
rs![DeptAppr] = currentuser
rs![DeptApprDate] = Date
rs.Update
rs.Requery
MsgBox "Credentials Verified! PR approved!"
Else
MsgBox "This approval has already been marked
approved!"
End If

rs.Close
Set rs = Nothing
db.Close
Set db = Nothing
Me.Requery

End Sub

Everything in this code seems to be working great, but
when it gets to the line for Me.Requery to refresh the
information on the form, it gives me a write conflict and
says that another user has made changes to the code. The
message says that "the record has been changed by another
user since you started editing it." It then asks if I'd
like to "Save Record" which seems to undo the changes that
I just made, "Copy to Clipboard" which is useless,
or "Drop Changes" which seems to have the desired affect.

The issue is that I want to be able to excecute the above
code without having this box come up.

Does anyone have any suggestions?

Thanks,

Chris
 
E

Emilia Maxim

Chris,

is the form based on the same data? Does it have controls for user
name and date? If so, the simplest way would be to just fill those
controls. They can be hidden (Visible=No) if you don't want the user
to see them. And in the form's OnCurrent event you could check the
approval and display a message if already approved.

Best regards
Emilia

Emilia Maxim
PC-SoftwareService, Stuttgart
http://www.maxim-software-service.de

Chris A. said:
I'm using the following code to update 2 fields in a table
with the current users information and the date:

Private Sub btnApprv1_Click()
Dim db As Database
Dim rs As Recordset
Dim currentuser As String
Dim strSQL As String

Set db = CurrentDb()

currentuser = Forms!frmLogin!txtUserName
Date = Now()
ID = Forms!PurchaseRequisition!PRID

strSQL = strSQL & "SELECT * FROM tblPR WHERE "
strSQL = strSQL & "PRID = " & Forms!
PurchaseRequisition!PRID

Set rs = db.OpenRecordset(strSQL)

DeptAppr = rs![DeptAppr]

If IsNull(DeptAppr) Then
rs.FindFirst "[PRID] = " & ID
rs.Edit
rs![DeptAppr] = currentuser
rs![DeptApprDate] = Date
rs.Update

This Requery is not needed:
 

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