PDA

Click to See Complete Forum and Search --> : [RESOLVED] Invalid Use of Null !


Alankar
Jun 3rd, 2005, 06:58 AM
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

Hack
Jun 3rd, 2005, 07:18 AM
On what line does this error occur?

kfcSmitty
Jun 3rd, 2005, 07:23 AM
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

Alankar
Jun 3rd, 2005, 07:28 AM
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

Hack
Jun 3rd, 2005, 08:05 AM
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.

ThanksThat 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.

Alankar
Jun 5th, 2005, 11:12 PM
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