Not sure, but I suspect IsNull isn't needed. I expect the IsDate function would return False with Null as well as any value that is not a date.
@Kev86; yes doing it as you describe is OK as long as you don't mind writing and maintaining basically the same code multiple times. If the tests are against different data types and I was going to use Minty's approach I'd might do this:
Code:
Public Function IsValid(var As Variant) As Boolean
IsValid = True
Select Case TypeName(var)
Case "Date"
If var < #1/1/2020# Or var > Now() Then IsValid = False
Case "Double" 'add cases for "Integer", "Long", "Single"?
If Len(var) <> 10 Or Left(var, 2) <> 85 Then IsValid = False
'or as per my post is it "85" and not 85?
Case "String"
If Len(var) <> 10 Or Left(var, 2) <> "85" Then IsValid = False
Case Else
IsValid = False
End Select
Debug.Print IsValid
End Function
I'm undecided about that function's return type given that I'm not actually using it.
Notes
- if you're really passing the # character, you're passing a string. Not a good idea for comparing numbers - "1111" > "22" is False. Your intent may be correctly interpreted by Access but it may not be.
- be careful comparing dates with Now. If you are storing only dates, the field's time value defaults to 00:00:00 whether you see it or not. Looks OK here though.