davesmith202
10-15-2008, 09:37 AM
I want to check a field and run some code only if it has something in it.
If Ad1 <> "" Or Ad1 <> Null Then
'My code
End If
Is that the right way to do it?
Thanks,
Dave
Kiwiman
10-15-2008, 09:40 AM
try this
If Ad1 <> "" Or isnull(Ad1) Then
'My code
End If
MSAccessRookie
10-15-2008, 09:40 AM
I want to check a field and run some code only if it has something in it.
If Ad1 <> "" Or Ad1 <> Null Then
'My code
End If
Is that the right way to do it?
Thanks,
Dave
That should work fine, but many people will advise you to use IsNull(Ad1) instead of Ad1 <> Null
See what I mean? Kiwiman already made my point. IsNull() is the Access Standard, but Acess will also accept <> Null as well.
davesmith202
10-15-2008, 09:56 AM
But wouldn't IsNull(Ad1) mean that if the Ad1 was Null then it will run 'My code?
Kiwiman
10-15-2008, 10:02 AM
Cheers MSAccessRookie - didn't know that one. Like most things in access there is more than one way to skin a cat.
Quie right Davesmith i should have put
AND NOT ISNULL(AD1)
apologies
gemma-the-husky
10-15-2008, 10:14 AM
you can combine these in one expression
if nz(ad1,vbnullstring) = vbnullstring then
nz converts a null value into whatever you like
here vbnullstring is a ms constant for "",
(ie its equivalent to
If nz(Ad1,"")="" Then
but is guaranteed to be application independent - ie if MS implements zls string in another way, you wouldn't need to convert your code.
if you are dealing with a numeric, then you can say instead
if nz(num1,0)=0 then etc
---
ie nz enables you to consider both a default (ignore) value AND the null value in one simple statement