Invalid use of Null

R

Radhika

I have the following code in the on Got Focus event procedure for Tumor
Description:

Private Sub Combo6_GotFocus()
If Me.TumorPresent Then
Me.[Tumor Description] = "N/A"
End If

End Sub

I get an error message saying 'Invalid use of null'

What am i doing wrong?
 
D

Dirk Goldgar

Radhika said:
I have the following code in the on Got Focus event procedure for Tumor
Description:

Private Sub Combo6_GotFocus()
If Me.TumorPresent Then
Me.[Tumor Description] = "N/A"
End If

End Sub

I get an error message saying 'Invalid use of null'

What am i doing wrong?


Is it possible for TumorPresent to be Null? If so, then try wrapping the
reference in the Nz() function:

If Nz(Me.TumorPresent, False) Then

If TumorPresent is yes/no (boolean) field, then it isn't possible for it to
be Null as stored in a table. However, if you are getting it from a query
that does an outer join, such a field could be Null (when there is no
matching record on that side of the join).
 
D

dgm

Radhika said:
I have the following code in the on Got Focus event procedure for Tumor
Description:

Private Sub Combo6_GotFocus()
If Me.TumorPresent Then
Me.[Tumor Description] = "N/A"
End If

End Sub

I get an error message saying 'Invalid use of null'

What am i doing wrong?


Me.TumorPresent is null. That's what the message is saying. The only test
you can do on a variable or value containing null is to use the IsNull
function. You can also use ( "" & variable ) which is a cheat I often use.
If null it returns a zero length string, otherwise the data. Also try the NZ
function. You might use:

If nz(Me.TumorPresent,false) then
 
R

Radhika

Thank you!

It works fine is one database, but if i use the same code in another db, i
get another error message saying 'Invalid procedure of arguement'.

I cannot understand why

Any help would be appreciated.

Dirk Goldgar said:
Radhika said:
I have the following code in the on Got Focus event procedure for Tumor
Description:

Private Sub Combo6_GotFocus()
If Me.TumorPresent Then
Me.[Tumor Description] = "N/A"
End If

End Sub

I get an error message saying 'Invalid use of null'

What am i doing wrong?


Is it possible for TumorPresent to be Null? If so, then try wrapping the
reference in the Nz() function:

If Nz(Me.TumorPresent, False) Then

If TumorPresent is yes/no (boolean) field, then it isn't possible for it to
be Null as stored in a table. However, if you are getting it from a query
that does an outer join, such a field could be Null (when there is no
matching record on that side of the join).

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 

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