Goal: create a status History table for Intervals
Reason: Status changes all the time, Need to track the interval in days that a order was within each status.
I have changed some object names to easier understand what I am trying to accomplish, here is what I have so far:
Running code produces an Error:
"The Macro or Function set to the BeforeUpdate or ValidationRule property for this field is preventing Microsoft Access from saving the data in the field"
Private Sub Form_AfterUpdate()
On Error GoTo Err_Form_AfterUpdate
If Me.CurStatus <> Me.NewStatus Or Me.CurStatusDetail <> Me.NewStatusDetail Then
UpdateHistoryTable
Else
End If
Exit_Form_AfterUpdate:
Exit Sub
Err_Form_AfterUpdate:
MsgBox Err.Description
Resume Exit_Form_AfterUpdate
End Sub
Sub UpdateHistoryTable()
On Error GoTo Err_UpdateHistoryTable
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb()
Set rs = db.OpenRecordset("StatusHistory" ' Change name appropriately
With rs
.AddNew
' Here is where you would specify what fields you want to add to your second table.
![OrderID] = Me.OrderID
![Status] = Me.CurStatus
![StatusDetail] = Me.CurStatusDetail
![StatusBeginDate] = Me.CurStatusDate
![StatusEndDate] = Date
![FullStatusName] = Me.CurStatus & ", " & Me.CurStatusDetail
![StatusInterval] = Date - Me.CurStatusDetail
.Update
.close
End With
UpdateCurrent
Exit_UpdateHistoryTable:
Exit Sub
Err_UpdateHistoryTable:
MsgBox Err.Description
Resume Exit_UpdateHistoryTable
End Sub
Sub UpdateCurrent()
On Error GoTo Err_UpdateCurrent
Me.CurStatus = Me.newStatus
Me.CurStatusDetail = Me.NewStatusDetail
If Me.StausDate > Me.StatusDetailDate Then
Me.CSTATUSDATE = Me.StatusDate
Else
Me.CSTATUSDATE = Me.StatusDetailDate
End If
Me.Refresh
Exit_UpdateCurrent:
Exit Sub
Err_UpdateCurrent:
MsgBox Err.Description
Resume Exit_UpdateCurrent
End Sub
Reason: Status changes all the time, Need to track the interval in days that a order was within each status.
I have changed some object names to easier understand what I am trying to accomplish, here is what I have so far:
Running code produces an Error:
"The Macro or Function set to the BeforeUpdate or ValidationRule property for this field is preventing Microsoft Access from saving the data in the field"
Private Sub Form_AfterUpdate()
On Error GoTo Err_Form_AfterUpdate
If Me.CurStatus <> Me.NewStatus Or Me.CurStatusDetail <> Me.NewStatusDetail Then
UpdateHistoryTable
Else
End If
Exit_Form_AfterUpdate:
Exit Sub
Err_Form_AfterUpdate:
MsgBox Err.Description
Resume Exit_Form_AfterUpdate
End Sub
Sub UpdateHistoryTable()
On Error GoTo Err_UpdateHistoryTable
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb()
Set rs = db.OpenRecordset("StatusHistory" ' Change name appropriately
With rs
.AddNew
' Here is where you would specify what fields you want to add to your second table.
![OrderID] = Me.OrderID
![Status] = Me.CurStatus
![StatusDetail] = Me.CurStatusDetail
![StatusBeginDate] = Me.CurStatusDate
![StatusEndDate] = Date
![FullStatusName] = Me.CurStatus & ", " & Me.CurStatusDetail
![StatusInterval] = Date - Me.CurStatusDetail
.Update
.close
End With
UpdateCurrent
Exit_UpdateHistoryTable:
Exit Sub
Err_UpdateHistoryTable:
MsgBox Err.Description
Resume Exit_UpdateHistoryTable
End Sub
Sub UpdateCurrent()
On Error GoTo Err_UpdateCurrent
Me.CurStatus = Me.newStatus
Me.CurStatusDetail = Me.NewStatusDetail
If Me.StausDate > Me.StatusDetailDate Then
Me.CSTATUSDATE = Me.StatusDate
Else
Me.CSTATUSDATE = Me.StatusDetailDate
End If
Me.Refresh
Exit_UpdateCurrent:
Exit Sub
Err_UpdateCurrent:
MsgBox Err.Description
Resume Exit_UpdateCurrent
End Sub