I have a VBA function that is basically along these lines:
Public Function JoinDateTime(DateTime As String, Time As String) As Date
Dim dtDate As Date
dtDate = CDate(Format(DateTime, "dd/mm/yyyy"))
dtDate = dtDate & " " & Format(Time, "hh:mm")
JoinDateTime = dtDate
End Function
It glues a date and a time together into a datetime value. (The real function has some more logic behind it.)
The problem is, I'd like to add handling for annoying values being passed to it. This is mostly for empty/null values - if DateTime is empty, return empty. If it's a text string returning #Error so it doesn't just fail silently seems like a good idea.
Problem is, I'm not sure how to do so. I'd thought about doing an early return, maybe something like shoving this at the start of the function:
If DateTime = Null or DateTime = "" Then
JoinDateTime = Null
End If
but it doesn't seem to consider that as a return and still executes the rest of the function.
Is there a way to do this? A better way, ideally?