Wayne:
The triggering of the AfterUpdate event doesn't necessarily mean a row has
been 'altered' only updated; in terms of the data content it can be exactly
as it was before. You might be interested in the following module:
''''module starts''''
' module basChangedRecord
' determines if data in a record edited
' in a form has actually been changed
Option Compare Database
Option Explicit
' arrays for storing values from recordsets
Dim aOldVals(), aNewVals()
Public Sub StoreOldVals(rst As DAO.Recordset)
' store values of current row in array
aOldVals = rst.GetRows()
End Sub
Public Sub StoreNewVals(rst As DAO.Recordset)
' store values of edited row in array
aNewVals = rst.GetRows()
End Sub
Public Function RecordHasChanged() As Boolean
Dim n As Integer, intlast As Integer
Dim var As Variant
Dim aOld(), aNew()
intlast = UBound(aOldVals) - 1
' loop through array of original values
' and store in new array
For Each var In aOldVals()
ReDim Preserve aOld(n)
aOld(n) = var
n = n + 1
Next var
n = 0
' loop through array of edited values
' and store in new array
For Each var In aNewVals()
ReDim Preserve aNew(n)
aNew(n) = var
' if any value has changed then return True
If Nz(aNew(n), 0) <> Nz(aOld(n), 0) Then
RecordHasChanged = True
Exit For
End If
n = n + 1
Next var
End Function
''''module ends''''
which works by storing the current values in a data structure then comparing
doing the same with the values after an update and comparing the contents of
each. Its called in a form's module like this:
''''module starts
Option Compare Database
Option Explicit
Private Sub Form_AfterUpdate()
Dim dbs As DAO.Database, rst As DAO.Recordset
Dim strSQL As String
strSQL = "SELECT * FROM MyTable WHERE MyID = " & Me.MyID
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(strSQL)
StoreNewVals rst
If RecordHasChanged() Then
MsgBox "Record has changed"
End If
End Sub
Private Sub Form_Current()
Dim dbs As DAO.Database, rst As DAO.Recordset
Dim strSQL As String
If Not Me.NewRecord Then
strSQL = "SELECT * FROM MyTable WHERE MyID = " & Me.MyID
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(strSQL)
StoreOldVals rst
End If
End Sub
''''module ends''''
The insertion of a new row is regarded as a 'change' as well as the editing
of an existing row.
Ken Sheridan
Stafford, England