Or do it in code in the Status control's AfterUpdate event procedure:
Dim cmd As ADODB.Command
Dim strSQL As String
Dim ctrl As Control
Set ctrl = Me.ActiveControl
Set cmd = New ADODB.Command
cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandType = adCmdText
strSQL = "UPDATE YourTable" & _
" SET Status = TRUE" & _
" WHERE YourTable.Record_ID = " & Me.Record_ID & _
" AND YourTable.Date < #" & _
FORMAT(Me.[Date],"yyyy-mm-dd") & "#"
cmd.CommandText = strSQL
If ctrl = True Then
cmd.Execute
End If
But what if the user makes a mistake and sets the Status control to True and
then reverses this by unchecking the check box? The prior records' Status
column will have already have been updated to True. Would it be better to
update the prior records to whatever the current record's Status control is
updated to, i.e. if the user checks it then the prior ones are updated to
True, if they uncheck it then they are all updated to False? If so amend the
SQL statement and call the Execute method unconditionally:
strSQL = "UPDATE YourTable" & _
" SET Status = " & Me.Status & _
" WHERE YourTable.Record_ID = " & Me.Record_ID & _
" AND YourTable.Date < #" & _
FORMAT(Me.[Date],"yyyy-mm-dd") & "#"
cmd.CommandText = strSQL
cmd.Execute
I've assumed that by "all records with dates earlier than this one" you mean
"all records with the same record_id and dates earlier than this one", not
all prior records of any record_id value.
BTW 'Date' should be avoided as a column name. It’s the name of a built in
function, so using it as an object name could cause confusion. Something
more specific such as 'TransactionDate', 'OrderDate' etc should be used.
Ken Sheridan
Stafford, England
clayton said:
It might be easier to provide an example of what i'm trying to do. Is this
possible?
I have a table with three fields:
Record_ID (pk)
Date (pk)
Status
Other_Field1
Other_Two
The status field is a yes/no (-1,0) check-box field.
In my form, i set up a sub-form so that i can view all records for a given
record_ID. I want to set up the "after update" event on the Status field to
say something like:
If the status of this record is YES, then all records with dates earlier
than this one should also have a Status equal to YES.