# VBA IsNull problem



## Kevin147 (Jul 16, 2007)

I have a VBA problem that I'd really appreciate some help with.

I have a form on an Access database (2003). I wish validate the absence of a home phone number by giving the user a choice, either to enter the phone number or save the record anyway.

The field [PhoneHomeNumber] is left blank at table and form levels (no default entry). The data type is text.

I have used the following VBA code.

Private Sub PhoneNumberHome_BeforeUpdate(Cancel As Integer)

Dim strMessage As String
Dim intOptions As Integer
Dim bytChoice As Byte

If IsNull(PhomeNumberHome) Then
strMessage = "You didn't enter a home phone number. Save anyway?"
intOptions = vbQuestion + vbOKCancel
bytChoice = MsgBox(strMessage, intOptions)

If bytChoice = vbCancel Then
PhoneNumberHome.SetFocus
Cancel = True
End If

End If

End Sub

It is not working. Any ideas please.


----------



## Rollin_Again (Sep 4, 2003)

Put a break point on the line *If IsNull(PhomeNumberHome) Then* and when the debug window pops up hover over the variable PhoneNumberHome to see what value or property it holds and adjust your code accordingly.

You may also want to try using *If PhoneNumberHome = "" then * to test for an empty string value instead of null property.

BTW...In your code is it possible you have a mispelling?? I assume PhomeNumberHome should be PhoneNumberHome?

If you need more help just zip and attach the DB to your next post.

Regards,
Rollin


----------

