0

I'm making a form with Microsoft Access and I'm trying to make an AfterUpdate event procedure for a field. I need to know if the value of that field is the default value (or if it's empy). I read that the default value of a field in VBA is Null so I made this:

Private Sub EB1_10_Val1_AfterUpdate()
    If Me.EB1_10_Val1.Value = Null Then
        MsgBox "hello"
    End If
End Sub

This didn't work so I tried this for when the user updates the value in the field and then erases it (empties the field)

Private Sub EB1_10_Val1_AfterUpdate()
    If Me.EB1_10_Val1.Value = Empty Then
        MsgBox "hello"
    End If
End Sub

The messages never pop up. On the other hand I tried changing the default value of the field to 0 but Its not working. The 0 doesn't appear in the field as default when in Form View.

2
  • Try checking with isnull(Me.EB1_10_Val1.Value) and isEmpty(Me.EB1_10_Val1.Value) Commented Jul 27, 2015 at 8:56
  • By the way: what kind of field is Me.EB1_10_Val1? Commented Jul 27, 2015 at 8:58

2 Answers 2

3

You can check if the field is empty with this expression:

If IsNull(Me.EB1_10_Val1.Value) Then
Sign up to request clarification or add additional context in comments.

Comments

0

In addition to solution provided by mielk, you can use Nz or Iif function to replace Null with default value.

Usage:

myVal = Nz(Me.SomTextBox, 0)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.