Hi Team
I have some data that changes and gets an update date whenever a field is changed.
I am trying to report when a row has changed.
I can get pretty close if I take out the update date using a group by in conjunction with a dedup query but am not convinced I am getting the correct values for the changed row for
update date and updatedby as I had to use the "last" function in the group by query.
Some sample data is below.
ID Name Update_Date Updated by Status Glob_App_Class Simp_act_ret_date Simp_class Display
9117 App 2014-02-10 11:12:18 714 Act Inter_Plat Maintain
9117 App 2014-02-28 17:45:07 118 Act Inter_Plat Strategic Y
9117 App 2014-03-15 07:02:14 859 InAct Invest Strategic Y
9117 App 2014-03-15 08:39:03 859 InAct Invest Strategic
9117 App 2014-03-19 00:51:52 880 Act Dep Strategic Y
9117 App 2014-03-28 09:15:58 714 Act Dep Retire Y
9117 App 2014-03-31 12:43:27 118 Act Inter_Plat Deprecated/Retire Y
113 Bridge 2014-02-20 10:52:36 252 Act Dep Invest
113 Bridge 2014-02-28 17:44:16 118 Act Dep Strategic Y
113 Bridge 2014-03-07 01:00:03 system Act Dep Strategic
113 Bridge 2014-03-07 09:01:16 system InAct Dep Strategic Y
113 Bridge 2014-03-08 09:01:13 system Act Inter_Plat Strategic/Invest Y
Currently I have the output as a spreadsheet format but ideally want it in the format below .
ID Name Update_Date Updated by Status Field Old Val New Val
9117 App 2014-02-28 17:45:07 118 Act Simp_Class Maintain Strategic
9118 App 2014-03-15 07:02:14 119 InAct Glob_app_Class Inter_Plat Invest
9117 App 2014-03-19 00:51:52 880 Act Glob_app_Class Invest Dep
The code I have thus far gets me to read the records and move next, I have had a couple of iterations of the code where it is now looking at a union query but it is the concept of comparing changes in field for a record that I can't get my head around.
Dim db As Database
Dim rsupdate As Recordset
Dim workingid As String
Dim workingName As String
Dim workingupdatedby As String
Dim workingupdated As String
Dim workingFieldNme As String
Dim workingFieldVal As String
Dim nxtworkingid As String
Dim nxtworkingName As String
Dim nxtworkingupdatedby As String
Dim nxtworkingFieldNme As String
Dim nxtworkingupdated As String
Dim nxtworkingFieldVal As String
Set db = CurrentDb
Set rsupdate = db.OpenRecordset("qApp Change His", dbOpenDynaset)
rsupdate.MoveLast
rsupdate.MoveFirst
workingid = ""
workingName = ""
workingupdatedby = ""
workingupdated = ""
workingFieldNme = ""
workingFieldVal = ""
nxtworkingid = ""
nxtworkingName = ""
nxtworkingupdatedby = ""
nxtworkingFieldNme = ""
nxtworkingupdated = ""
nxtworkingFieldVal = ""
Do While Not rsupdate.EOF
workingid = rsupdate!AssetID
workingName = rsupdate!Asset_Name
workingupdatedby = rsupdate!updatedby
workingupdated = rsupdate!Updated
workingFieldNme = rsupdate!FieldName
workingFieldVal = rsupdate!FieldVal
If workingid <> rsupdate!AssetID And workingupdated <> rsupdate!Updated Then
workingid = ""
workingName = ""
workingupdatedby = ""
workingFieldNme = ""
workingupdated = ""
rsupdate.MoveNext
End If
If workingid = rsupdate!AssetID And workingupdated = rsupdate!Updated Then
rsupdate.MoveNext
nxtworkingid = rsupdate!AssetID
nxtworkingName = rsupdate!Asset_Name
nxtworkingupdatedby = rsupdate!updatedby
nxtworkingFieldNme = rsupdate!FieldName
nxtworkingFieldVal = rsupdate!FieldVal
nxtworkingupdated = rsupdate!Updated
If rsupdate!AssetID = nxtworkingid Then
If workingstatus <> nxtworkingstatus Then
ChangedField = "Status"
OLDVal = workingstatus
NewVal = nxtworkingstatus
'rsupdate.MoveNext
End If
End If
End If
newupdatedby = ""
newupdateby = rsupdate!updatedby
'no need for an else just Insert into
'rsupdate.MoveNext
Loop
End Sub
any help appreciated.
I have some data that changes and gets an update date whenever a field is changed.
I am trying to report when a row has changed.
I can get pretty close if I take out the update date using a group by in conjunction with a dedup query but am not convinced I am getting the correct values for the changed row for
update date and updatedby as I had to use the "last" function in the group by query.
Some sample data is below.
ID Name Update_Date Updated by Status Glob_App_Class Simp_act_ret_date Simp_class Display
9117 App 2014-02-10 11:12:18 714 Act Inter_Plat Maintain
9117 App 2014-02-28 17:45:07 118 Act Inter_Plat Strategic Y
9117 App 2014-03-15 07:02:14 859 InAct Invest Strategic Y
9117 App 2014-03-15 08:39:03 859 InAct Invest Strategic
9117 App 2014-03-19 00:51:52 880 Act Dep Strategic Y
9117 App 2014-03-28 09:15:58 714 Act Dep Retire Y
9117 App 2014-03-31 12:43:27 118 Act Inter_Plat Deprecated/Retire Y
113 Bridge 2014-02-20 10:52:36 252 Act Dep Invest
113 Bridge 2014-02-28 17:44:16 118 Act Dep Strategic Y
113 Bridge 2014-03-07 01:00:03 system Act Dep Strategic
113 Bridge 2014-03-07 09:01:16 system InAct Dep Strategic Y
113 Bridge 2014-03-08 09:01:13 system Act Inter_Plat Strategic/Invest Y
Currently I have the output as a spreadsheet format but ideally want it in the format below .
ID Name Update_Date Updated by Status Field Old Val New Val
9117 App 2014-02-28 17:45:07 118 Act Simp_Class Maintain Strategic
9118 App 2014-03-15 07:02:14 119 InAct Glob_app_Class Inter_Plat Invest
9117 App 2014-03-19 00:51:52 880 Act Glob_app_Class Invest Dep
The code I have thus far gets me to read the records and move next, I have had a couple of iterations of the code where it is now looking at a union query but it is the concept of comparing changes in field for a record that I can't get my head around.
Dim db As Database
Dim rsupdate As Recordset
Dim workingid As String
Dim workingName As String
Dim workingupdatedby As String
Dim workingupdated As String
Dim workingFieldNme As String
Dim workingFieldVal As String
Dim nxtworkingid As String
Dim nxtworkingName As String
Dim nxtworkingupdatedby As String
Dim nxtworkingFieldNme As String
Dim nxtworkingupdated As String
Dim nxtworkingFieldVal As String
Set db = CurrentDb
Set rsupdate = db.OpenRecordset("qApp Change His", dbOpenDynaset)
rsupdate.MoveLast
rsupdate.MoveFirst
workingid = ""
workingName = ""
workingupdatedby = ""
workingupdated = ""
workingFieldNme = ""
workingFieldVal = ""
nxtworkingid = ""
nxtworkingName = ""
nxtworkingupdatedby = ""
nxtworkingFieldNme = ""
nxtworkingupdated = ""
nxtworkingFieldVal = ""
Do While Not rsupdate.EOF
workingid = rsupdate!AssetID
workingName = rsupdate!Asset_Name
workingupdatedby = rsupdate!updatedby
workingupdated = rsupdate!Updated
workingFieldNme = rsupdate!FieldName
workingFieldVal = rsupdate!FieldVal
If workingid <> rsupdate!AssetID And workingupdated <> rsupdate!Updated Then
workingid = ""
workingName = ""
workingupdatedby = ""
workingFieldNme = ""
workingupdated = ""
rsupdate.MoveNext
End If
If workingid = rsupdate!AssetID And workingupdated = rsupdate!Updated Then
rsupdate.MoveNext
nxtworkingid = rsupdate!AssetID
nxtworkingName = rsupdate!Asset_Name
nxtworkingupdatedby = rsupdate!updatedby
nxtworkingFieldNme = rsupdate!FieldName
nxtworkingFieldVal = rsupdate!FieldVal
nxtworkingupdated = rsupdate!Updated
If rsupdate!AssetID = nxtworkingid Then
If workingstatus <> nxtworkingstatus Then
ChangedField = "Status"
OLDVal = workingstatus
NewVal = nxtworkingstatus
'rsupdate.MoveNext
End If
End If
End If
newupdatedby = ""
newupdateby = rsupdate!updatedby
'no need for an else just Insert into
'rsupdate.MoveNext
Loop
End Sub
any help appreciated.