Login form (1 Viewer)

sbaud2003

Member
Local time
Tomorrow, 00:11
Joined
Apr 5, 2020
Messages
170
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, 18:41
Joined
Feb 19, 2013
Messages
16,553
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, 18:41
Joined
Jul 21, 2014
Messages
2,237
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
Tomorrow, 00:11
Joined
Apr 5, 2020
Messages
170
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