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!
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!