conditional update not working

mcgraw

Registered User.
Local time
Today, 09:53
Joined
Nov 13, 2009
Messages
77
I am an infant when dealing with databases or coding, let me just put that out there up front. :)

I am trying to put an If statement into a set of code that will update a field only if the status = "closed".

Here's the code I have:

Private Sub Status_AfterUpdate()

Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("StatusChange")
With rs
.AddNew
!ID_tblIssues = Me.ID
!Status_Old = Status_Old
!Change_Status = Me.Status
.Update
End With
Me.SetFocus
Me.Category.SetFocus
Forms![Issue_Details]![frmStatusChange].Requery
exitline:
If Not rs Is Nothing Then
rs.Close
Set rs = Nothing
End If

Set rs = CurrentDb.OpenRecordset("Issues")
With rs
If Status = "Closed" Then
.Edit
!Close_Dt = Now()
.Update

rs.Close
Set rs = Nothing
End If
End With
Exit Sub


The first part of this works without a problem, but I can't get the part in bold (If Status = "Closed") part to work. The weird thing is SOMETIMES it gives me an error that someone else has already modified the record, and I may overwrite, but I am the only person in the DB (local copy on my PC, so I am 100% positive of that).

What am I doing wrong? Thanks!
 
What does status refer to? Is is it a form control? If so, put me!status
 
Yes, this is on AfterUpdate on a field in a form.

I put the me!Status in there, and all I am getting is the error that another user already updated it, do I want to save record. When I say save record, the close_dt still doesn't update?

Is it because I am running the status change log before this?
 

Users who are viewing this thread

Back
Top Bottom