Skip to content

Working with Dates in Code

Q:  Martin Wichmand writes:

I’m trying to make some conditional formatting with VBA, using the following line of code to pop up a message box if the date in the control is today’s date or later:

   If IsDate(Me![cboOpfoelgning].Value) >= Dato() Then
 

But I just get an error.

A:  The problem here is that the IsDate function takes a True or False value, not a date.  And (to make absolutely sure that the date comparison will work), you should use the CDate function as well, to convert the value in the control to a Date.  Try this instead:

   If IsDate(Me![cboOpfoelgning].Value) = True Then

      If CDate(Me![cboOpfoelgning].Value) >= Dato() Then

About this author