LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default Comparing Dates

I am trying to compare two fields... one is a textbox and the other is a cell
range.

textbox : tbDateOOCreated.Value
range : Range("Db_Updated").Value

I am loading them into date variables and making a comparison in an if
statement

CreateDt = tbDateOOCreated.Value
UpdateDt = Range("Db_Updated").Value

If CreateDt < UpdateDt Then
:: Code ::
end if

The problem I am having is, if they are dates, and the textbox value is
empty, I get a type mismatch error.

if I use a function to fix the value...

CreateDt = FixDate(tbDateOOCreated.Value)
UpdateDt = FixDate(Range("Db_Updated").Value)

Function...
Public Function FixDate(DumbDate As Variant) As Variant

Dim dAns As Variant

If Not IsDate(DumbDate) Then
dAns = Null
ElseIf CStr(DumbDate) = "12:00:00 AM" Then
dAns = Null
Else
dAns = CDate(DumbDate)
End If

FixDate = dAns

End Function


I tried using a Function to fix the date and load a Null, but I get an
invalid use of null.

How can I compare these two fields as dates?

Thanks for the help!
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparing dates Gareth.Evans Excel Worksheet Functions 0 March 26th 09 08:54 AM
Comparing dates Gareth.Evans Excel Worksheet Functions 3 March 25th 09 07:05 PM
Comparing 2 Dates JWeaver Excel Worksheet Functions 3 August 14th 08 09:01 PM
Comparing dates Mr. Dan[_2_] Excel Programming 3 February 8th 06 07:29 AM
Comparing dates Debbie F Excel Worksheet Functions 7 September 7th 05 11:57 AM


All times are GMT +1. The time now is 03:01 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"