non zero / is null problems - Error 94 - invalid use of null (1 Viewer)

Keith Nichols

Registered User.
Local time
Today, 06:35
Joined
Jan 27, 2006
Messages
431
Lots and lots of posts on this subject so it is something that obviously gives lots of trouble to newbies such as myself.

The code below works fine if the control is not null but gives Error 94 - invalid use of null when the control is null. I have gone around in circles with this - what am I doing wrong?


Code:
PrjNumber = Me!Projectnumber
        If IsNull(PrjNumber) Then
            MsgBox "Project number is null "
        Else: PrjNumber = " project " & PrjNumber
            MsgBox "Project number is not null "
        End If
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 04:35
Joined
Sep 12, 2006
Messages
15,660
the error is occurring at the first statement - if projectnumber is null this line will fail immediately.

Code:
[COLOR="Red"]'this produces an erorr immediately
PrjNumber = Me!Projectnumber[/COLOR]


i assume prjnumber is a string, from your subsequent use so instead use nz function and try

Code:
if nz(projectnumber,0)=0 then
            MsgBox "Project number is null "
Else PrjNumber = " project " & projectnumber
            MsgBox "Project number is not null "
End If
 
Last edited:

Keith Nichols

Registered User.
Local time
Today, 06:35
Joined
Jan 27, 2006
Messages
431
Thanks Gemma,

I shall go a way and play!
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 04:35
Joined
Sep 12, 2006
Messages
15,660
i've just noticed an error in my code, and modified it slightly
 

Keith Nichols

Registered User.
Local time
Today, 06:35
Joined
Jan 27, 2006
Messages
431
Thanks Gemma,

This worked for me:
Code:
        If Nz(Projectnumber, 0) = 0 Then                'Test for null project number
                    PrjNumber = ""
            Else: PrjNumber = " Project: " & Projectnumber
        End If
:D
 

Users who are viewing this thread

Top Bottom