Hi,
I've got a question that probably has a pretty simple answer, but I didn't find a solution yet. Here's an example:
Public Function abc(var_1 As Variant) As Single
abc = 2 * var_1
End Function
I want to call that function in an Access query. Values for 'var_1' are from a numeric (single) data field. Problem: Some the values for var_1 are empty/missing. For those values I need the result of the function to be empty as well, but right now they are '0'.
I tried a lot of things already, but nothing works. The result for empty values is always '0' and not empty. Here's one try:
If IsNull(var_1) Then
abc = Empty
Exit Function
End If
Didn't work.
Any help for this problem would be very much appreciated. :)
Edit:
Thanks for the answers. I tried returning a variant before and it did return empty fields. However, the calculated field needs to behave as numberic and not as text, so this solution doesn't work for me. I ended up using the answer of Beth, though it's more work than I'd like to have. ;) Calling the function in SQL:
IIF(IsNull(X)=False;abc(X))
abc in VBA:
Public Function abc(var_1 As Single) As Single
abc = 2 * var_1
End Function