Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 09-09-2013, 06:13 PM   #1
gbil
Newly Registered User
 
Join Date: Aug 2013
Location: Zamboanga City, Philippines
Posts: 26
Thanks: 13
Thanked 1 Time in 1 Post
gbil is on a distinguished road
If End If Construct

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?

gbil is offline   Reply With Quote
Old 09-09-2013, 07:10 PM   #2
Galaxiom
Super Moderator
 
Join Date: Jan 2009
Location: NSW Australia
Posts: 11,656
Thanks: 98
Thanked 1,500 Times in 1,415 Posts
Galaxiom is a splendid one to behold Galaxiom is a splendid one to behold Galaxiom is a splendid one to behold Galaxiom is a splendid one to behold Galaxiom is a splendid one to behold Galaxiom is a splendid one to behold Galaxiom is a splendid one to behold
Re: If End If Construct

Null cannot be tested with the equals operator.

Test for both Null and Null String with:

If Len(Me!cboOrgNick & vbNullString) = 0
Galaxiom is offline   Reply With Quote
The Following User Says Thank You to Galaxiom For This Useful Post:
gbil (09-09-2013)
Old 09-09-2013, 07:28 PM   #3
gbil
Newly Registered User
 
Join Date: Aug 2013
Location: Zamboanga City, Philippines
Posts: 26
Thanks: 13
Thanked 1 Time in 1 Post
gbil is on a distinguished road
Re: If End If Construct

Quote:
Null cannot be tested with the equals operator.
oh i did not know that.

thank you Galaxiom. the code now terminates properly.


gbil is offline   Reply With Quote
Old 09-10-2013, 08:03 AM   #4
TJPoorman
Newly Registered User
 
Join Date: Jul 2013
Posts: 402
Thanks: 0
Thanked 135 Times in 131 Posts
TJPoorman is on a distinguished road
Re: If End If Construct

you could also do

Code:
If nz(Me!cboOrgNick, "") = "" Then
This basically converts a null string to ""
TJPoorman is offline   Reply With Quote
Old 09-10-2013, 03:09 PM   #5
Galaxiom
Super Moderator
 
Join Date: Jan 2009
Location: NSW Australia
Posts: 11,656
Thanks: 98
Thanked 1,500 Times in 1,415 Posts
Galaxiom is a splendid one to behold Galaxiom is a splendid one to behold Galaxiom is a splendid one to behold Galaxiom is a splendid one to behold Galaxiom is a splendid one to behold Galaxiom is a splendid one to behold Galaxiom is a splendid one to behold
Re: If End If Construct

Quote:
Originally Posted by TJPoorman View Post
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.

Galaxiom is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help construct Report. djchapple Reports 6 08-31-2011 08:32 AM
? to construct a complex DAO query CharlesWhiteman Modules & VBA 2 06-03-2010 06:15 AM
help to construct a query liangtp Queries 2 03-25-2009 10:48 PM
Need help with junction table(s) construct Shep General 4 04-13-2007 11:17 PM
What construct should I use? Malcy Modules & VBA 8 10-27-2003 10:33 AM




All times are GMT -8. The time now is 01:56 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World