If End If Construct

gbil

Registered User.
Local time
Today, 15:18
Joined
Aug 30, 2013
Messages
26
Hello.

i have this code:

Private Sub cboOrgNick_LostFocus()
'making auto-populate textbox with incremental numbering
'if combo box is not empty
If Me!cboOrgNick = "" Or Me!cboOrgNick = Null Then
Exit Sub
'do nothing or
Else
'get new number
Me![nMembNum] = NewMembNum()
'prevent user from selecting the field
Me![tFName].SetFocus
End If

End Sub

even though cboOrgNick is empty (Null in debug window) it continue to execute after the Else Clause, executing the NewMembNum().

why is the construct do not exit even if is true?
 
Null cannot be tested with the equals operator.

Test for both Null and Null String with:

If Len(Me!cboOrgNick & vbNullString) = 0
 
Null cannot be tested with the equals operator.

oh i did not know that.

thank you Galaxiom. the code now terminates properly.

:)
 
you could also do

Code:
If nz(Me!cboOrgNick, "") = "" Then

This basically converts a null string to ""
 
you could also do

Code:
If nz(Me!cboOrgNick, "") = "" Then

This basically converts a null string to ""

"" is the NullString.

The Nz expression posted converts a Null to a NullString.
 

Users who are viewing this thread

Back
Top Bottom