Login Form + Code

Peterh

New member
Local time
Today, 14:57
Joined
Nov 14, 2006
Messages
2
I have been attempting to create a log-in form. I have the code it just does not work. Could someone please look over what I have and let me know where I have made a mistake. I have pasted the code.

Private Sub Command4_Click()
'Variable Declaration Section
Dim db As Database, rs As Recordset
Dim result
Dim SQLline
'Variable Definition Section
SQLline = "SELECT * FROM tbl-first WHERE Username = [Username]AND Password =[Password];"
Set db = CurrentDb()
Set rs = db.OpenRecordset(SQLline)
'Processing Logic Section
If Username = result![Username] = [Username] And result![Password] = [Password] Then
MsgBox "Welcome!"
Else
MsgBox "Username and Password do not Match. Access Denied!"
End If
result.Close
End Sub
 
try this

SQLline = "SELECT * FROM tbl-first WHERE Username = " & chr(34) & [Username] & chr(34) & " AND Password = " & chr(34) & [Password] & chr(34)
 
This actually did not help, it did give me ideas on expanding on this code though. I am still trying to get the code to run properly.
 
I use a login page in a few of my DB's. This is my method -

Uses controls 'txtPassword' and 'cboEmployee' to verify name and password. It may help.

If Me.txtPassword.Value = DLookup("Password", "tblEmployees", "[Employee_No]=" & Me.cboEmployee.Value) Then

'Password ok, do something

Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
Me.txtPassword.SetFocus
End If

'If User Enters incorrect password 3 times database will shutdown

intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
MsgBox "You do not have access to this database. Please contact your system administrator.", vbCritical, "Restricted Access!"
Application.Quit
End If
 
Using ADO Connection

Using ADO Connection is more faster than using DAO.
Here is a sample of password checking using ADO for your reference.

Private Sub cmdOK_Click()
CurUser = UCase(Me.txtUserName)
rs.Open "Select * from User_SecurityInfo where UserID= '" & CurUser & "'", db, adOpenDynamic, adLockBatchOptimistic
If rs.EOF Then
MsgBox "Invalid Username/Password, try again!", , "Login"
rs.Close
txtPassword.SetFocus
SendKeys "{Home}+{End}"
Exit Sub
End If
If txtPassword = rs.Fields("Password") Then
CurGroup = rs.Fields("UserGroup")
LoginSucceeded = True
rs.Close
Set rs = db.Execute("Update User_SecurityInfo Set LastLogin =#" & Now() & "# where UserID= '" & CurUser & "'")
Unload Me
Unload frmSplash
MainWindow.Show
Else
MsgBox "Invalid Username/Password, try again!", , "Login"
rs.Close
txtPassword.SetFocus
SendKeys "{Home}+{End}"
End If
End Sub

Private Sub Form_Load()
db.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "..\Data\DMCAIS.mdb;Persist Security Info=False"
End Sub
 

Users who are viewing this thread

Back
Top Bottom