Hi, Can anyone help I have this login form where I enter a username and password to login which works fine but I would like to change the way I login, is there a way where I can just enter my password and it searches the access database and finds and shows the username. Below is what I have at the moment.
VBA Code:
Private Sub txtPass_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 13 Then
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim qry As String
qry = "SELECT * FROM StoresNames WHERE Name = '" & Me.txtUser.Value & "'"
cnn.Open "provider=Microsoft.ace.oledb.12.0;Data Source=" & ThisWorkbook.Path & "\DataBase.mdb"
rst.Open qry, cnn, adOpenKeyset, adLockPessimistic
If rst.RecordCount = 0 Then
MsgBox "Incorrect User ID"
txtUser = ""
txtUser.SetFocus
rst.Close
cnn.Close
Exit Sub
ElseIf rst.Fields("Tag").Value = Me.txtPass.Value Then
rst.Close
cnn.Close
Unload Me
Else
MsgBox "Incorrect Password"
txtPass = ""
txtPass.SetFocus
rst.Close
cnn.Close
End If
End If
End Sub