You will never be able to get Null from a string parameter/variable in VBA.
In SQL or via a recordset, the data type nvarchar & Co can already contain Null, but not a String parameter/variable in VBA.
Note: However, I recommend always adding the default value (except for Variant, if you want to check IsMissing), as this makes the code easier to read in my opinion. Even if it would not be necessary with vbNullstring, for example.
In SQL or via a recordset, the data type nvarchar & Co can already contain Null, but not a String parameter/variable in VBA.
Public Sub TestMe(Optional ByVal x as String)
:TestMe Null
=> Error: Invalid use of NullCall TestMe()
=> x is empty (vbNullstring) but not NullNote: However, I recommend always adding the default value (except for Variant, if you want to check IsMissing), as this makes the code easier to read in my opinion. Even if it would not be necessary with vbNullstring, for example.
Public Sub TestMe(Optional ByVal x as String = vbNullString, Optional Byval y as Long = 0)
is easier to read because you don't have to think about the default value of the respective type.
Last edited: