Essentially, you'd just need to append the new data from its source, whatever that may be, and in the 'append' query include a column which has the date value to be inserted into a column which identifies each subset of rows. Say for instance you are
importing data from somewhere, do so into a into a pre-defined 'holding' table which you empty first with:
DELETE *
FROM HoldingTable;
Having imported the new data into this table you can then append from it into your single operational table, which will include an additional column of date/time data type; let's call it TransactionDate. For simplicity in this example I'll again restrict the
data to FirstName and LastName columns. Let's say you want to insert the current date as TransactionDate when you append the data, the query would be like this:
INSERT INTO OperationalTable(TransactionDate, FirstName, LastName)
SELECT DATE(), FirstName, LastName
FROM HoldingTable;
Or you might want to enter a date value when you execute the query:
PARAMETERS [Enter transaction date:] DATETIME;
INSERT INTO OperationalTable(TransactionDate, FirstName, LastName)
SELECT [Enter transaction date:], FirstName, LastName
FROM HoldingTable;
You can compare the rows from one date to another by amending my function a little:
Public Function CompareVals(lngID As Long, dtmTransactionDate As Date, ParamArray CurrentVals() As Variant) As String
Dim rst As DAO.Recordset
Dim strSQL As String
Dim n As Integer
Dim var As Variant
strSQL = "SELECT FirstName,LastName FROM OperationalTable " & _
"WHERE MyID = " & lngID & " AND TransactionDate = #" &_
Format(dtmTransactionDate,"yyyy-mm-dd") & "#"
Set rst = CurrentDb.OpenRecordset(strSQL)
For n = 0 To 1
If CurrentVals(n) <> rst.Fields(n) Then
CompareVals = CompareVals & ", " & rst.Fields(n).Name & ":" & CurrentVals(n)
End If
Next n
CompareVals = Mid(CompareVals, 3)
End Function
When calling the function in a query you'd then have parameters for the two dates to be compared, e.g. today's and yesterday's:
PARAMETERS [Today's date:] DATETIME,
[Yesterday's date:] DATETIME;
SELECT TransactionDate, MyID,
CompareVals(MyID,[Yesterday's date:],FirstName,LastName) AS Changes
FROM OperationalTable
WHERE TransactionDate = [Today's date:]
AND LEN(CompareVals(ContactID,Firstname,LastName)) > 0;
MyID cannot now be the primary key of the table of course as its values will not be distinct. The primary key will now be a composite one of MyID and TransactionDate.