Form Coding Issue

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have this simple procedure and it isn't working. I am sure it is something
really simple that I just haven't considered. I could program it another way
but I just want to know why it is not working as planned. I have a form with
a field [fldName] that's control source is a query. Here is the code:

Private Sub Form_Load()

If Me.fldName.Value = Null Then
cmdLogin.Enabled = False
MsgBox "You are not an authorized user. Access Denied!", vbOKOnly,
"Bye"
DoCmd.Quit
End If
End Sub

Any suggestions?
 
"Anything = Null" will always return False. Null isn't "equal to" anything,
ever, so nothing can ever "equal" Null.

In the words of Yoda: "There is no 'Equal'. Null Is or Is Not." (Or
something like that...)

Ahem. Try this instead:
If IsNull(Me.fldName.Value) Then

HTH,
 
I have this simple procedure and it isn't working. I am sure it is something
really simple that I just haven't considered. I could program it another way
but I just want to know why it is not working as planned. I have a form with
a field [fldName] that's control source is a query. Here is the code:

Private Sub Form_Load()

If Me.fldName.Value = Null Then
cmdLogin.Enabled = False
MsgBox "You are not an authorized user. Access Denied!", vbOKOnly,
"Bye"
DoCmd.Quit
End If
End Sub

Any suggestions?

What do you mean by the 'control source is a query'?
Do you mean the Form's Record Source is a query and there is a fldName
field in that Record Source?

If IsNull(Me![fldName]) Then
etc.....
End If
 
Thanks George! :-)

That's what I was after. I tried the "If me.fldName.value = false" as well
but it didn't work, either. But the "If IsNull(Me.fldName.Value)" Then did.

Thanks again.


George Nicholson said:
"Anything = Null" will always return False. Null isn't "equal to" anything,
ever, so nothing can ever "equal" Null.

In the words of Yoda: "There is no 'Equal'. Null Is or Is Not." (Or
something like that...)

Ahem. Try this instead:
If IsNull(Me.fldName.Value) Then

HTH,
--
George Nicholson

Remove 'Junk' from return address.


Leftyleolady said:
I have this simple procedure and it isn't working. I am sure it is
something
really simple that I just haven't considered. I could program it another
way
but I just want to know why it is not working as planned. I have a form
with
a field [fldName] that's control source is a query. Here is the code:

Private Sub Form_Load()

If Me.fldName.Value = Null Then
cmdLogin.Enabled = False
MsgBox "You are not an authorized user. Access Denied!", vbOKOnly,
"Bye"
DoCmd.Quit
End If
End Sub

Any suggestions?
 
Back
Top