Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2004
    Posts
    3

    Unanswered: Oldvalue doesn't hold null values

    I'm trying to track changes to the value of a field. When I change the value from null to any non-null value, oldvalue is set to 1. Here's the code:

    Private Sub TransDishBarrelCCount_BeforeUpdate(Cancel As Integer)
    If IsNull(Me!TransDishBarrelCCount.Value) And Not IsNull(Me!TransDishBarrelCCount.OldValue) Then
    MsgBox "Value set to null."
    ElseIf Not IsNull(Me!TransDishBarrelCCount.Value) And (IsNull(Me!TransDishBarrelCCount.OldValue) Or Me!TransDishBarrelCCount.OldValue = "") Then
    MsgBox "Value changed from null or empty."
    ElseIf Me!TransDishBarrelCCount.Value <> Me!TransDishBarrelCCount.OldValue Then
    MsgBox "Value Changed"
    End If
    End Sub

    I keep getting the message 'Value changed." when it should say "Value changed from null of empty."

    What am I doing wrong???

    Thanks

  2. #2
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713

    Re: Oldvalue doesn't hold null values

    Originally posted by elinor1127
    I'm trying to track changes to the value of a field. When I change the value from null to any non-null value, oldvalue is set to 1. Here's the code:

    Private Sub TransDishBarrelCCount_BeforeUpdate(Cancel As Integer)
    If IsNull(Me!TransDishBarrelCCount.Value) And Not IsNull(Me!TransDishBarrelCCount.OldValue) Then
    MsgBox "Value set to null."
    ElseIf Not IsNull(Me!TransDishBarrelCCount.Value) And (IsNull(Me!TransDishBarrelCCount.OldValue) Or Me!TransDishBarrelCCount.OldValue = "") Then
    MsgBox "Value changed from null or empty."
    ElseIf Me!TransDishBarrelCCount.Value <> Me!TransDishBarrelCCount.OldValue Then
    MsgBox "Value Changed"
    End If
    End Sub

    I keep getting the message 'Value changed." when it should say "Value changed from null of empty."

    What am I doing wrong???

    Thanks
    OldValue doesn't get set until the record has been saved ...
    Microsoft Access uses the OldValue property to store the original value of a bound control. When you edit a bound control on a form, your changes aren't saved until you move to another record. The OldValue property contains the unedited version of the underlying data.

  3. #3
    Join Date
    Jan 2004
    Posts
    3
    Thanks for the info.

    Rats! I was trying to come up with a way to check for changes to the value of a data entry field as the form was being filled out. Any suggestions anybody???

  4. #4
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Originally posted by elinor1127
    Thanks for the info.

    Rats! I was trying to come up with a way to check for changes to the value of a data entry field as the form was being filled out. Any suggestions anybody???
    Only thing I can think to do is save off the original value in the before-update and test against that value with the new value in the after_update ...

  5. #5
    Join Date
    Jan 2004
    Posts
    3
    I tried setting a variable to the value in the before update event and then comparing it to the new value in the after update event. Didn't work.

    Thanks for trying!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •