Full Version: Null vs. "" vs. Len ???
UtterAccess Discussion Forums > Access Knowledge Center > Access Knowledgebase / FAQ
ALaRiva
I was just searching the FAQs page and didn't find anything on this and was wondering if any of the UA Rulers would be so kind as to put up a post explaining the difference between:

Null
Len of 0 and
""

I think this would help alot of us - or at least it would help me -
R. Hicks
This is from Access Help files:

The difference between Null values and zero-length strings

Microsoft Access allows you to distinguish between two kinds of blank values, because in some situations, a field may be left blank because the information may exist but is not currently known, or it may be left blank because it doesn't apply to the record at all. For example, if a table has a Fax Number field, you may leave the field blank because you don't know if a customer has a fax number, or you may leave it blank because you know that the customer doesn't have a fax number. In this case, leaving the field blank enters a Null value which means "I don't know." Entering a zero-length string by typing double quotation marks (" ") means "I know that there is no value."

Len() is a function the returns the number of characters in a string.

HTH
RDH
mishej
In addition to the information that Ricky posted, I commonly use a technique to determine if a variable or control has a non-null, non-empty value:

If Len(Me.txtLastName & vbNullString) > 0 Then

If the txtLastName control is Null, then the vbNullString ("") aka "empty string" is appended to it which results in, voila, an empty string which would have a Len() of 0.

If the txtLastName control is an empty string then the two empty strings are concantenated together resulting in, voila, an empty string which would have a Len() of 0.

Therefore anything that got past the If statement would contain a value. Microsoft recommends using this technique as a "performance enhancement" over other methods of determining a non-null, non-empty value in a control or Variant variable.

Here is some good reading along with additional tips.
germargo
Currently I use this coding for same purpose:
If IsNull(Me.txtLastName) Or Me.txtLastName = ”” Then

Opposite statement:
If Not IsNull(Me.txtLastName) Or Me.txtLastName <> ”” Then

This way I checking a null value(never was entered in field) or information was deleted.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.