VBA code in MS Access - testing bound text box for Null

Hi Experts,

I'm using VBA code in MS Access.

I've got a bound text box, Organization, that is on a subform.

I'm referencing it by Forms!Clients!Organization.

It works fine, as long as it is not Null.

How can I test if it is Null in an If statement?

I've got this code now:

If Forms!Clients!Organization = Null Then
   MsgBox "You have not specified Company/Organization."
   Exit Sub
End If

Open in new window


But when Forms!Clients!Organization is Null, the If evaluates to False.

Regards,
Leigh
LVL 1
LeighWardleAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

John TsioumprisSoftware & Systems EngineerCommented:
If its really Null then
If IsNull(Forms!Clients!Organization ) then

Open in new window

but sometimes Null is not exacty Null so i use
If Len(Nz(Forms!Clients!Organization,""))>0  then

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LeighWardleAuthor Commented:
Thanks, John.

You are worth your weight in Gold!

Regards,
Leigh
1
John TsioumprisSoftware & Systems EngineerCommented:
This is rather dangerous statement since we are talking about a lot of weight....lets say the scale has a hard time when i visit her..:)
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

LeighWardleAuthor Commented:
Hi John,

Just for the record:

I needed to change > 0 to = 0 in the If statement:

If Len(Nz(Forms!Clients!Organization,"")) =  0  then

Open in new window


That works for the text box when it is Null, also when it consists of spaces...
0
John TsioumprisSoftware & Systems EngineerCommented:
If you have spaces then you need one more command...to clear the spaces
If Len(Nz(Trim(Forms!Clients!Organization),"")) =  0  then

Open in new window

0
Dale FyeCommented:
except if it is NULL, Trim will raise an error:

I use a function which makes it very clear what you are trying to test for, and has the added benefit of having less key strokes than the other options.

If IsNullOrBlank(Forms!Clients!Organization) then

Public Function IsNullOrBlank(SomeValue as Variant) as boolean

    IsNullOrBlank = Trim(SomeValue & " ") = ""

End Function

Open in new window

0
John TsioumprisSoftware & Systems EngineerCommented:
Good point Dale..so my code should be
If Len(Trim(Nz(Forms!Clients!Organization,""))) =  0  then

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.