Code prevents a write conflict

  • Thread starter Thread starter Max
  • Start date Start date
M

Max

I have the following code in the after update field of a subform that
prompts the user to change all dates if more than one record is present.

The code runs and changes the records, but I get a write conflict when I try
to close the main form when more than one record is present in the subform.
It appears that the Update is not saving the record.

Any suggestions?

Thanks in advance,
Max

'If date changed prompt to set all dates to the same for existing procedures
Dim rs As Recordset, Response As Integer, Msg As String, ProcDate As Date

ProcDate = Me.ProcedureDate

Set rs = Me.RecordsetClone
rs.MoveLast
If rs.RecordCount <= 1 Then Exit Sub

Msg = "Do you want to set all procedures to this date?"
Response = MsgBox(Msg, vbQuestion + vbYesNo + vbDefaultButton1, "Date
changes")
If Response = vbNo Then Exit Sub

With rs
.MoveFirst
Do Until .EOF
.Edit
![ProcedureDate] = ProcDate
.Update
.MoveNext
Loop
End With
rs.Close
 
Max said:
I have the following code in the after update field of a subform that
prompts the user to change all dates if more than one record is
present.

The code runs and changes the records, but I get a write conflict
when I try to close the main form when more than one record is
present in the subform. It appears that the Update is not saving the
record.

Any suggestions?

Thanks in advance,
Max

'If date changed prompt to set all dates to the same for existing
procedures Dim rs As Recordset, Response As Integer, Msg As String,
ProcDate As Date

ProcDate = Me.ProcedureDate

Set rs = Me.RecordsetClone
rs.MoveLast
If rs.RecordCount <= 1 Then Exit Sub

Msg = "Do you want to set all procedures to this date?"
Response = MsgBox(Msg, vbQuestion + vbYesNo + vbDefaultButton1,
"Date changes")
If Response = vbNo Then Exit Sub

With rs
.MoveFirst
Do Until .EOF
.Edit
![ProcedureDate] = ProcDate
.Update
.MoveNext
Loop
End With
rs.Close

What event is this code running in? If it's the AfterUpdate event of
the form (well, of the form that is being displayed as a subform), I'd
expect it to work unless there's some other code operating. If it's not
running in the form's AfterUpdate event, then maybe you need to insert
the line

If Me.Dirty Then Me.Dirty = False

before you do anything else in that procedure.
 
Thanks,
This was a useful lead, but it generated different errors that I think I can
fix.

Max

Dirk Goldgar said:
Max said:
I have the following code in the after update field of a subform that
prompts the user to change all dates if more than one record is
present.

The code runs and changes the records, but I get a write conflict
when I try to close the main form when more than one record is
present in the subform. It appears that the Update is not saving the
record.

Any suggestions?

Thanks in advance,
Max

'If date changed prompt to set all dates to the same for existing
procedures Dim rs As Recordset, Response As Integer, Msg As String,
ProcDate As Date

ProcDate = Me.ProcedureDate

Set rs = Me.RecordsetClone
rs.MoveLast
If rs.RecordCount <= 1 Then Exit Sub

Msg = "Do you want to set all procedures to this date?"
Response = MsgBox(Msg, vbQuestion + vbYesNo + vbDefaultButton1,
"Date changes")
If Response = vbNo Then Exit Sub

With rs
.MoveFirst
Do Until .EOF
.Edit
![ProcedureDate] = ProcDate
.Update
.MoveNext
Loop
End With
rs.Close

What event is this code running in? If it's the AfterUpdate event of
the form (well, of the form that is being displayed as a subform), I'd
expect it to work unless there's some other code operating. If it's not
running in the form's AfterUpdate event, then maybe you need to insert
the line

If Me.Dirty Then Me.Dirty = False

before you do anything else in that procedure.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
Back
Top