Results 1 to 6 of 6

Thread: [RESOLVED] Invalid Use of Null !

Hybrid View

  1. #1

    Thread Starter
    Member Alankar's Avatar
    Join Date
    Jun 2005
    Location
    Ghaziabad, India
    Posts
    40

    Resolved [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
    Last edited by Alankar; Jun 20th, 2005 at 12:33 AM.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Invalid Use of Null !

    On what line does this error occur?

  3. #3
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    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

  4. #4

    Thread Starter
    Member Alankar's Avatar
    Join Date
    Jun 2005
    Location
    Ghaziabad, India
    Posts
    40

    Talking 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

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  6. #6

    Thread Starter
    Member Alankar's Avatar
    Join Date
    Jun 2005
    Location
    Ghaziabad, India
    Posts
    40

    Resolved 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
    Last edited by Alankar; Jun 8th, 2005 at 12:36 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width