Can Form_BeforeUpdate detect a specific control change?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In Form_BeforeUpdate event I want to check if a specific control had been
changed. This is for a business rule, if x has changed and y then CancelEvent.
Thanks.
 
Doug said:
In Form_BeforeUpdate event I want to check if a specific control had
been changed. This is for a business rule, if x has changed and y
then CancelEvent. Thanks.

If Me!ControlName <> Me!ControlName.OldValue Then...
 
If Me!ControlName <> Me!ControlName.OldValue Then...

..OldValue, like .Text, is only available when the control has the
focus, if I'm not mistaken.

You have to do this kind of validation in the controls themselves.

The one way to do this is to open a snapshot recordset when the
record is loaded, and compare the values to that. Or to populate an
array that stores the values in the controls before they've been
changed. Or to use a set of flags set in the events of the
individual controls that tell you if you the values have changed.
 
The control does not need to have the focus. You can test the OldValue
property in the Form_BeforeUpdate event as in Rick's example. You do need to
allow for the possibility of Null values, though ..

Private Sub Form_BeforeUpdate(Cancel As Integer)

If Nz(Me.TestNum2.Value) <> Nz(Me.TestNum2.OldValue) Then
MsgBox "Oh, no you don't!"
Cancel = True
End If

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top