Reputation: 341
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.
Upvotes: 0
Views: 1943
Reputation: 8591
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)
Upvotes: 0
Reputation: 3940
You can check if the field is empty with this expression:
If IsNull(Me.EB1_10_Val1.Value) Then
Upvotes: 3