Type RecValues
NUMBERPRGN As String
TH_STATUS As String
SYSMODTIME As Date
DATE_ENTERED As Date
WEEK_STATUS As String
End Type
Sub Moveinto()
Dim MyDB As DAO.Database
Dim MyRS As DAO.Recordset
Dim MyTable As DAO.TableDef
Dim MyRec As DAO.Recordset
Dim x As String
Set MyDB = CurrentDb
Set MyTable = MyDB.TableDefs!Retreived_Data
With MyTable
.Fields.Append .CreateField("WEEK_STATUS", dbText, 7)
End With
Set MyRS = MyDB.OpenRecordset("Retreived_Data", dbOpenDynaset)
Set MyRec = MyDB.OpenRecordset("Retreived_Data", dbOpenTable)
With MyRS
.MoveFirst
.Requery
While Not .EOF
x = CStr(Year(.Fields("SYSMODTIME").Value) & "w" & Format(Format(.Fields("SYSMODTIME").Value, "ww"), "00"))
.Edit
!WEEK_STATUS = x
.Update
Debug.Print .Fields(0).Value & .Fields(4).Value
.MoveNext
Wend
End With
Set MyRec = MyDB.OpenRecordset("Retreived_Data", dbOpenTable)
Dim OldRec As RecValues
Dim NewRec As RecValues
Dim RecToAdd As Integer
Dim Adder As Integer
With MyRec
.MoveFirst
'First Record Values
OldRec.DATE_ENTERED = .Fields(3).Value
OldRec.NUMBERPRGN = .Fields(0).Value
OldRec.SYSMODTIME = .Fields(2).Value
OldRec.TH_STATUS = .Fields(1).Value
OldRec.WEEK_STATUS = .Fields(4).Value
While Not (.EOF)
.MoveNext
If .EOF Then
Exit Sub
End If
'New Record Values
NewRec.DATE_ENTERED = .Fields(3).Value
NewRec.NUMBERPRGN = .Fields(0).Value
NewRec.SYSMODTIME = .Fields(2).Value
NewRec.TH_STATUS = .Fields(1).Value
NewRec.WEEK_STATUS = .Fields(4).Value
RecToAdd = CInt(Right(NewRec.WEEK_STATUS, 2)) - CInt(Right(OldRec.WEEK_STATUS, 2))
'Compare Values
If NewRec.NUMBERPRGN = OldRec.NUMBERPRGN Then
If Left(OldRec.WEEK_STATUS, 4) = Left(NewRec.WEEK_STATUS, 4) Then
Adder = 0
ElseIf Left(OldRec.WEEK_STATUS, 4) < Left(NewRec.WEEK_STATUS, 4) Then
Adder = 52
End If
If RecToAdd + Adder > 1 Then
For I = 1 To RecToAdd - 1
.AddNew
![NUMBERPRGN] = OldRec.NUMBERPRGN
![TH_STATUS] = OldRec.TH_STATUS
![SYSMODTIME] = OldRec.SYSMODTIME
![DATE_ENTERED] = OldRec.DATE_ENTERED
![WEEK_STATUS] = Left(OldRec.WEEK_STATUS, 5) & Format(CInt(Right(OldRec.WEEK_STATUS, 2) + I), "00")
.Update
Next I
End If
End If
OldRec.DATE_ENTERED = NewRec.DATE_ENTERED
OldRec.NUMBERPRGN = NewRec.NUMBERPRGN
OldRec.SYSMODTIME = NewRec.SYSMODTIME
OldRec.TH_STATUS = NewRec.TH_STATUS
OldRec.WEEK_STATUS = NewRec.WEEK
Wend
End With
End Sub