Syntax for Is Not Null ?

C

CW

When one of our forms is opened (Current event) I want a message box fired by
certain conditions (that the Ref control does have a value, but the Country
control is empty). I have tried various bits of code along the lines shown
below, but keep getting runtime errors. Wot's wrong with the following,
please?

If [Me.Ref] is not null and [Me.Country] = "" Then MsgBox "Please enter the
country!"

Many thanks
CW
 
D

Daryl S

CW -

Try this:

If (not isnull([Me.Ref])) AND IsNull([Me.Country]) Then MsgBox "Please enter
the
country!"
 
R

Rick Brandt

CW said:
When one of our forms is opened (Current event) I want a message box fired
by certain conditions (that the Ref control does have a value, but the
Country control is empty). I have tried various bits of code along the
lines shown below, but keep getting runtime errors. Wot's wrong with the
following, please?

If [Me.Ref] is not null and [Me.Country] = "" Then MsgBox "Please enter
the country!"

Many thanks
CW

These are for queries...
[SomeField] Is Null
[SomeField] Is Not Null

In VBA Code use...
IsNull(SomeValue)
Not IsNull(SomeValue)
 
C

CW

Thanks - that seems to work, except that the MsgBox appears before the form
opens, and seems to be modal i.e. prevents the form actually opening until
the msg box is closed. I am using On Current, but I have tried On Load too -
is there some other event to which I could attach this code and it would then
not fire the message until the form was actually open?
Many thanks
CW

Rick Brandt said:
CW said:
When one of our forms is opened (Current event) I want a message box fired
by certain conditions (that the Ref control does have a value, but the
Country control is empty). I have tried various bits of code along the
lines shown below, but keep getting runtime errors. Wot's wrong with the
following, please?

If [Me.Ref] is not null and [Me.Country] = "" Then MsgBox "Please enter
the country!"

Many thanks
CW

These are for queries...
[SomeField] Is Null
[SomeField] Is Not Null

In VBA Code use...
IsNull(SomeValue)
Not IsNull(SomeValue)

.
 
D

Daryl S

CW -

You can try the GotFocus event of the first control (in tab order) on your
form.
--
Daryl S


CW said:
Thanks - that seems to work, except that the MsgBox appears before the form
opens, and seems to be modal i.e. prevents the form actually opening until
the msg box is closed. I am using On Current, but I have tried On Load too -
is there some other event to which I could attach this code and it would then
not fire the message until the form was actually open?
Many thanks
CW

Rick Brandt said:
CW said:
When one of our forms is opened (Current event) I want a message box fired
by certain conditions (that the Ref control does have a value, but the
Country control is empty). I have tried various bits of code along the
lines shown below, but keep getting runtime errors. Wot's wrong with the
following, please?

If [Me.Ref] is not null and [Me.Country] = "" Then MsgBox "Please enter
the country!"

Many thanks
CW

These are for queries...
[SomeField] Is Null
[SomeField] Is Not Null

In VBA Code use...
IsNull(SomeValue)
Not IsNull(SomeValue)

.
 
S

Sylvain Lafontaine

You are always seeing this message probably because the recordset is empty
or that you are on a new record. You should check for these two
possibilities before testing for individual values.

--
Sylvain Lafontaine, ing.
MVP - Windows Live Platform
Blog/web site: http://coding-paparazzi.sylvainlafontaine.com
Independent consultant and remote programming for Access and SQL-Server
(French)


CW said:
Thanks - that seems to work, except that the MsgBox appears before the
form
opens, and seems to be modal i.e. prevents the form actually opening until
the msg box is closed. I am using On Current, but I have tried On Load
too -
is there some other event to which I could attach this code and it would
then
not fire the message until the form was actually open?
Many thanks
CW

Rick Brandt said:
CW said:
When one of our forms is opened (Current event) I want a message box
fired
by certain conditions (that the Ref control does have a value, but the
Country control is empty). I have tried various bits of code along the
lines shown below, but keep getting runtime errors. Wot's wrong with
the
following, please?

If [Me.Ref] is not null and [Me.Country] = "" Then MsgBox "Please enter
the country!"

Many thanks
CW

These are for queries...
[SomeField] Is Null
[SomeField] Is Not Null

In VBA Code use...
IsNull(SomeValue)
Not IsNull(SomeValue)

.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top