Question : Problem handling Nulls in Access VBA Function

Hello EE:
I created a function similar to Nz() where I want to return a value if a field is "", " ", or null.  But it's not handling the nulls and giving me a #error.  Can you point out what I'm missing?

Thanks,
LVBarnes
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
Public Function Tn(txt1 As String, repltxt As String) As String 
    Dim txt2 As String
        If txt1 = "" Or txt1 = " " Then
            txt2 = repltxt
        ElseIf IsNull(txt1) = True Then
            txt2 = repltxt
        Else
            txt2 = txt1
        End If
        
        Tn = txt2

End Function

Answer : Problem handling Nulls in Access VBA Function

You have to declare txt1 as a Variant:

Public Function Tn(txt1 As Variant, repltxt As String) As String
    Dim txt2 As String
        If txt1 = "" Or txt1 = " " Then
            txt2 = repltxt
        ElseIf IsNull(txt1) = True Then
            txt2 = repltxt
        Else
            txt2 = txt1
        End If
       
        Tn = txt2

End Function
Random Solutions  
 
programming4us programming4us