Login form (1 Viewer)

sbaud2003

Member
Local time
Today, 09:29
Joined
Apr 5, 2020
Messages
96
Hi I have created a login form with user ID and the Password Text Box
The problem is that while putting the password it accepts the password o any available password and loin into the system . I am not getting how the vba code is below:

Public Sub Login()

'Option Compare Binary
Dim TempUserLogin As TempVar

On Error GoTo ErrorHandler:
If IsNull(Me.txtuserid.value) Or Me.txtuserid.value = "" Then

MsgBox "You must enter a User ID", vbOKOnly + vbInformation, "UserID Required"

Me.txtuserid.SetFocus

Exit Sub

End If
If IsNull(Me.tp.value) Or Me.tp.value = "" Then

MsgBox "You must enter a Password", vbOKOnly + vbInformation, "Password Required"

Me.tp.SetFocus

Exit Sub

End If

If (IsNull(DLookup("UserName", "tblUsers", "StrComp(UserName, '" & Me.txtuserid.value & "', 0) = 0"))) Or _

(IsNull(DLookup("Password", "tblUsers", "StrComp(Password, '" & Me.tp.value & "', 0) = 0"))) Then


Me.txtuserid.value = ""

Me.tp.value = ""

Me.txtuserid.SetFocus

intLogAttempt = intLogAttempt + 1

MsgBox "Invalid UserName Or Password!!!! Yor are left with another " & 5 - [intLogAttempt] & " Attempt to Login" & vbCrLf & "User ID and the Password both are case sensitive!!!", vbOKOnly + vbCritical, "UNAUTHORISED ACCESS"

txtuserid.value = ""

tp.value = ""

txtuserid.SetFocus


Else



TempVars!TempUserLogin = Me.txtuserid.value

strUser = Me.txtuserid.value 'Set the value of strUser declared as Global Variable

strRole = DLookup("Role", "tblUsers", "[UserName]='" & Me.txtuserid.value & "'") 'set the value of strRole declared as Global Variable

strMyname = DLookup("Uname", "tblUsers", "[UserName]='" & Me.txtuserid.value & "'")

STRUNIT = DLookup("unit", "UNIT", "[Current] = True")


DoCmd.Close acForm, Me.NAME, acSaveNo

DoCmd.OpenForm "SWITCHBOARD", acNormal


End If


'Check if the user has 3 wrong log-in attempts and close the application

If intLogAttempt = 5 Then

MsgBox "You missed five (5) times Loging Attempt,You do not have access to this Database.Please contact Admin." & vbCrLf & vbCrLf & _

"Application will Exit.", vbCritical, "Access Denied!!!!"

Application.Quit

End If

ErrorHandler:


End Sub
 

CJ_London

Super Moderator
Staff member
Local time
Today, 03:59
Joined
Feb 19, 2013
Messages
12,603
please repost using the code tags (see the insert button on the ribbon)

Almost impossible to understand your code without the indentation
 

cheekybuddha

AWF VIP
Local time
Today, 03:59
Joined
Jul 21, 2014
Messages
557
Hi,

Code tags would definitely have made this code easier to read!

Your initial problem is here:
Code:
' ...
  If (IsNull(DLookup("UserName", "tblUsers", "StrComp(UserName, '" & Me.txtuserid.value & "', 0) = 0"))) Or _
     (IsNull(DLookup("Password", "tblUsers", "StrComp(Password, '" & Me.tp.value & "', 0) = 0"))) Then
' ...

You probably should do it all in one:
Code:
' ...
  If IsNull(DLookup("UserName", "tblUsers", "StrComp(UserName, '" & Me.txtuserid.value & "', 0) = 0 AND StrComp(Password, '" & Me.tp.value & "', 0) = 0")) Then
' ...

However, since you are looking for so many values from the table it might be easier to use a recordset.
 
Last edited:

sbaud2003

Member
Local time
Today, 09:29
Joined
Apr 5, 2020
Messages
96
Hi,

Code tags would definitely have mad this code easier to read!

Your initial problem is here:
Code:
' ...
  If (IsNull(DLookup("UserName", "tblUsers", "StrComp(UserName, '" & Me.txtuserid.value & "', 0) = 0"))) Or _
     (IsNull(DLookup("Password", "tblUsers", "StrComp(Password, '" & Me.tp.value & "', 0) = 0"))) Then
' ...

You probably should do it all in one:
Code:
' ...
  If IsNull(DLookup("UserName", "tblUsers", "StrComp(UserName, '" & Me.txtuserid.value & "', 0) = 0 AND StrComp(Password, '" & Me.tp.value & "', 0) = 0")) Then
' ...

However, since you are looking for so many values from the table it might be easier to use a recordset.
 

Users who are viewing this thread

Top Bottom