[RESOLVED] Invalid Use of Null !
Hi All,
I am using following code written on a button click event on a user Login form in Access-2003 VBA.
Code -----------------------------------------------------
Private Sub cmdLogin_Click()
'Login procedure
Dim PasswordData As String
LoginName = txtUserName
Password = txtUserPass
PasswordData = DLookup("[UserPass]", "tbuser", "[UserName] = forms!Login!txtusername")
'PasswordData = DLookup("[UserPass]", "tbUser", "[UserName] = Login")
If Password = PasswordData Then
Call LoginFunction
Else
MsgBox "Sorry, your username or password was incorrect." & vbCrLf & vbCrLf & "Unable to login.", vbCritical, "Login Error"
End If
End Sub
-----------------------------------------Code
I have a table named tbUser and fields UserName, UserPass and UserPrev in this table. I want to get Passworddata where login Name match with any record in the table. When control comes to DLookup function an error Invalid Use of Null is raised. I can't guess what is the problem.
Anyone please help.
Alankar
Re: Invalid Use of Null !
On what line does this error occur?
Re: Invalid Use of Null !
The error in itself means you're most likely pulling a null value out of your table.
This usually happens when I forget to tell it to stop at EOF.
Make sure its not trying to pull any null values from the table
Re: Invalid Use of Null !
Hi Hack,
This error occurs where I call DLookup function. But I got the problem.
As kfcSmitty guessed it was trying to get some record which is not there actually.
Thanks
Re: Invalid Use of Null !
Quote:
Originally Posted by Alankar
Hi Hack,
This error occurs where I call DLookup function. But I got the problem.
As kfcSmitty guessed it was trying to get some record which is not there actually.
Thanks
That is what I suspected as well, but I thought it was because a field contained Null data, not because a record was actually not there.
Re: Invalid Use of Null !
Hi Hack,
I have replaced the line as folloing to avoid this error. Now it is working fine.
----------------------Code-------------------
PasswordData = IIf(IsNull(DLookup("[tbUser]![UserPass]", "[tbuser]", "[tbUser]![UserName] = forms!Login!txtusername")), 0, DLookup("[tbUser]![UserPass]", "[tbuser]", "[tbUser]![UserName] = forms!Login!txtusername"))
----------------------Code---------------------
Thanks for help !
Alankar