return a null value to date field

L

LGarcia

Hi all,
I took a stab at writing a function. I am comparing 2 date fields. I need to
return either the latest date or which ever one isn't null. If both are null
then leave it blank. I'm getting an invalid use of null error. Hope someone
can help. Here's the code:

Thanks,
LGarcia

Function GrantsDate(strSubmitDate, strAwardDate) As Variant

Dim strReportDate As Variant

If IsNull(strSubmitDate) And IsNull(strAwardDate) Then
strReportDate = Null '********gives invalid use of null error*******
End If

If IsNull(strSubmitDate) And Not IsNull(strAwardDate) Then
strReportDate = strAwardDate
End If

If Not IsNull(strSubmitDate) And IsNull(strAwardDate) Then
strReportDate = strSubmitDate
End If

If Not IsNull(strSubmitDate) And Not IsNull(strAwardDate) Then
If strSubmitDate > strAwardDate Then
strReportDate = strSubmitDate
Else
strReportDate = strAwardDate
End If
End If

GrantsDate = strReportDate

End Function
 
K

kc-mass

If you want to leave the field blank when both fields are null then
instead of assigning as "= Null" assign as a zero length string as "="".
 
L

LGarcia

thanks!
sorry for the double post!

kc-mass said:
If you want to leave the field blank when both fields are null then
instead of assigning as "= Null" assign as a zero length string as "="".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top