Null Value

A

asa

Hi

I know this may sound simple.
I'm trying to check for a field if it is null. If null->display message.I
try using the Validation rule in the properties of the field but unable to do.
The field is from a datasheet and it is like a combo-box where user will
select the value given.
Also, how can I ensure that user do not enter any new item. They can only
choose from the selection given.
Thks so much for the help.
 
G

Graham R Seach

To check for a Null value, use the control's BeforeUpdate event:
Private Sub txtMyTextBox_BeforeUpdate(Cancel As Integer)
If IsNull(Me!txtMyTextBox.Text) Then
MsgBox "Null value"
Me!txtMyTextBox.Undo
Cancel = True
End If
End Sub

To ensure the user only selects/enters a valid value from the list:
http://www.pacificdb.com.au/MVP/Code/NIL.htm

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
A

Avlan

It's tricky, I found it difficult to understand when you could use Null
and when you couldn't. I found the nZ-function rather usefull:

The syntax for the Nz function is:

---
Nz ( variant, [ value_if_null ] )

variant is a variable that is a variant datatype.

value_if_null is optional. It is the value to use when the variant is
a null value. If this parameter is omitted and the variant is a null
value, the Nz function will return a zero or a zero-length string.

For example:

Nz (varName, "n/a")

The example above would return the value 'n/a' if the variable varName
contained a null value.

Nz (varName)

The example above would return a zero-length string if the variable
varName contained a null value.
 
Top