Invalid Use of Null

I sometimes get the Run time error 94 - invalid use of Null

Private Sub txtDOB_AfterUpdate()
  Me.txtDOB = CDate(Me.txtDOB))
End Sub
' *****

I changed the code to the one below the error disappear but I am not too sure if this was the right code.

 Me.txtDOB = CDate(Nz(Me.txtDOB))
LVL 4
billcuteAsked:
Who is Participating?
 
aikimarkConnect With a Mentor Commented:
1. if this is a bound control, MSAccess will not allow non-date data to be entered.
2. proper protective code example:
Private Sub txtDOB_AfterUpdate()
  If IsNull(Me.txtDOB) Then
  Else
    Me.txtDOB = CDate(Me.txtDOB))
  End If
End Sub
0
 
GRayLCommented:
You have to remember that while a date can be null, the function Cdate always has to work off a number.  
CDate(null) will always yield an error message.
0
 
billcuteAuthor Commented:
aikimark,
Your code works fine.

Regards
Bill
0
 
billcuteAuthor Commented:
GrayL / aikimark,
If you have time, I will appreciate it if you can take a look at some of my other posts that are currently open.

Regards
Bill
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.