"LAS" <(E-Mail Removed)> wrote in
news:i5125e$qmc$(E-Mail Removed):
> I'm trying to come up with a standard way to deal with the problem
> that some things allow nulls and others don't, and it's taxing my
> brain to try to keep them straight. I'm thinking about using
> variants in all my function parameters, and dealing with them,
> depending on need, something like I have below. Are there
> downsides to this?
>
> Public Function fncTotalByOther(av_CodeGroup As Variant, av_Where
> As Variant) As String
>
> On Error GoTo Err_TotalByOther
>
> fncTotalByOther = "Bad data"
>
> If Nz(av_CodeGroup) = "" Then
> MsgBox ("fncTotalByOther: Code_Group is empty")
> Exit Function
> End If
>
> av_Where = Nz(av_Where,"")
Your code is not checking for Null, so it won't work.
My principle is this:
For functions that get called in rows of a SQL statement, if the
fields you're passing them can be Null, then use variant data types.
For all other subs/functions, I don't use variant data types except
if the data is variant (which is pretty uncommon and not that easy
to deal with).
I often use functions in rows of a SQL statement that are passed
fields that can be Null, but the problems can be avoided by
concatenating the field value with an empty string or using Nz().
Basically, I avoid variants because they are somewhat unpredictable
and because it violates the rule of strong data typing, which I
consider more important than mere convenience. That means that when
using them, I have to think about the data I'm passing them and act
accordingly.
--
David W. Fenton
http://www.dfenton.com/
contact via website only
http://www.dfenton.com/DFA/