Run code off a change_record event ?

  • Thread starter Thread starter Chris James
  • Start date Start date
C

Chris James

I have a form who's source is a table with a boolean Y/N field .
The form displays the table in datasheet view .
I want to run some code when the user changes any record's value for the Y/N
field .
( the code will be summing the total Yes count for all of the records ,
...... no prob. ) .
How do I 'trip' into the code from the user action ?

Thanks
 
Chris James said:
I have a form who's source is a table with a boolean Y/N field .
The form displays the table in datasheet view .
I want to run some code when the user changes any record's value for the Y/N
field .
( the code will be summing the total Yes count for all of the records ,
..... no prob. ) .
How do I 'trip' into the code from the user action ?

You need a few things here. Add a variable (BoolFieldChange as Boolean) to
the declarations section of your form's module. That will make the
variable available to all code in the module.

In the BeforeUpdate event of the form...

If Me!BooleanFieldName <> Me!BooleanFieldName.OldValue Then
BoolFieldChange = True
End If

In the AfterUpdate event of the Form.

If BoolFieldChange = True Then
(run your code)
BoolFieldChange = False
End If

If the code is fairly quick to run, you could just run it every time in the
form's AfterUpdate event and dispense with the variable, BeforeUpdate code,
and the If-Then block.
 
Back
Top