Determine if updated record in new access vb
In Microsoft Access, you can use the DLookUp
function to determine if a record has been updated. Here's an example:
Suppose you have a table called Customers
with a field called LastUpdated
that stores the date and time the record was last updated. You can use the following query to determine if a record has been updated:
DLookUp("LastUpdated", "Customers", "CustomerID = " & Me.CustomerID)
This will return the value of the LastUpdated
field for the record with the matching CustomerID
. If the record has been updated, the value will be different from the previous update date.
You can also use the DCount
function to count the number of records with the same CustomerID
and a different LastUpdated
value:
DCount("*, ""CustomerID = """ & Me.CustomerID & """ AND LastUpdated <> """ & Me.LastUpdated & """", "Customers")
If the count is greater than 0, it means the record has been updated.
In VBA, you can use the DLookUp
function in a similar way:
Dim updated As Date
updated = DLookUp("LastUpdated", "Customers", "CustomerID = " & Me.CustomerID)
If updated <> Me.LastUpdated Then
' Record has been updated
Else
' Record has not been updated
End If
Alternatively, you can use the DAO
object to determine if a record has been updated:
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb()
Set rs = db.OpenRecordset("Customers")
rs.FindFirst "CustomerID = " & Me.CustomerID
If Not rs.NoMatch Then
If rs!LastUpdated <> Me.LastUpdated Then
' Record has been updated
Else
' Record has not been updated
End If
End If
Note that these examples assume you have a form with a CustomerID
control and a LastUpdated
control that displays the last updated date. You'll need to modify the code to match your specific form and table structure.