View Full Version : Null Value


andygriffin
05-26-2002, 07:17 AM
Hi all

Apologies if this is in the wrong forum - the question involves a query and a form.

Brief background - this is some code involving carrying out an action depending on the results of a query to be active on the open event of the main form in the database. The form is not based on a table.

There is a hidden text box on the form which captures the users Windows NT NetID when they open the form.

Inserted into the form is a subform which is based on a query which returns the users information which is stored in a table in the database, and is returned via the stored NetID value on the main form.

What I am trying to do is disable a button if the user's captured NetID does not exist in the table.

What I have tried to use is variations of:

If Me!frmUserinfo!Usernetid Is Null Then
Me!Button1.enabled = False
Else: Me!Button1.enabled = True
End If

The idea behind this is to give everybody access to the database, but only registered users (Entered into a table by admin) will have access to Button1. The idea being that the query determines that the user is not registered because it returns no values (the netid is not found in the table) and so the subform, and specifically the netid field, contains no value.

But I can't get this to work!!

I have tried the following:

If Me!frmUserinfo!Usernetid Is Null Then
Me!Button1.enabled = False
Else: Me!Button1.enabled = True
End If
(this throws an error)

If Me!frmUserinfo!Usernetid = Null Then
Me!Button1.enabled = False
Else: Me!Button1.enabled = True
End If
(this doesn't do anything)

If Me!frmUserinfo!Usernetid = "" Then
Me!Button1.enabled = False
Else: Me!Button1.enabled = True
End If
(this doesn't work)

All help is gratefully appreciated!

Andy.

DBL
05-26-2002, 07:31 AM
Try

If IsNull (Me!frmUserinfo!Usernetid) or Me!frmUserinfo!Usernetid = 0 Then

if UserID is a numeric field, then it might have 0 as the default value so technically it's never "null".

Also you might have to refer to the subform by:

Forms!MainFormName!frmUserInfo!UsernetID

or

Forms!MainFormName!frmUserInfo.Forms!Usernetid

andygriffin
05-26-2002, 07:50 AM
Thank you for the response... unfortunately I can not rely on the 0 value as the field is a text field. So I'll try the first option you suggested.

Referencing the subform is fine.

Cheers

Andy