We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,497 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

small error please help

Private Sub Command4_Click()
Dim vPass As String
 If IsNull([usernametxt]) = True Then
        MsgBox "Username is required", vbOKOnly, "Required Data"
        
    ElseIf IsNull([answertxt]) = True Then
        MsgBox "Password is required", vbOKOnly, "Required Data"

End If
' Evaluate filter before it is passed to DLookup function.
     strFilter = "[USERNAME]= '" & Me.usernametxt & "' And [ANSWER]= '" & Me.answertxt & "'"

    ' Look up product's unit price and assign it to the UnitPrice control.
     vPass = DLookup("PASSWORD", "SYS_USER", strFilter)

If IsNull(vPass) = False Then
Me.passwordtxt.Value = vPass
Else
MsgBox "You have entered an incorrect username or answer."
End If
End Sub

i use this code to run a forget password in a login system.
it works just fine, but have one error if u entered wrong information it gives me invalid use of null and points at(vPass = DLookup("PASSWORD", "SYS_USER", strFilter).

2
Contributors
1
Reply
1 Day
Discussion Span
2 Years Ago
Last Updated
2
Views
deadelgabar
Light Poster
31 posts since Apr 2010
Reputation Points: -1
Solved Threads: 0
Skill Endorsements: 0

Your variable "vPass" should be type "variant".

You may also wish to exit the sub if you have invalid entries, like so:

Private Sub Command4_Click()
Dim vPass As Variant           '<------------------------ Should be variant, not string datatype
If IsNull([usernametxt]) = True Then
    MsgBox "Username is required", vbOKOnly, "Required Data"
    Exit Sub                   '<------------------------ Leave Subroutine on invalid username
ElseIf IsNull([answertxt]) = True Then
    MsgBox "Password is required", vbOKOnly, "Required Data"
    Exit Sub                   '<------------------------ Leave Subroutine on invalid answer text
End If
' Evaluate filter before it is passed to DLookup function.
strFilter = "[USERNAME]= '" & Me.usernametxt & "' And [ANSWER]= '" & Me.answertxt & "'"

' Look up product's unit price and assign it to the UnitPrice control.
vPass = DLookup("PASSWORD", "SYS_USER", strFilter)

If IsNull(vPass) = False Then
    Me.passwordtxt.Value = vPass
Else
    MsgBox "You have entered an incorrect username or answer."
End If

End Sub

Hope this helps.

BitBlt
Practically a Posting Shark
894 posts since Feb 2011
Reputation Points: 482
Solved Threads: 148
Skill Endorsements: 14

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0580 seconds using 2.66MB