My Assistant
![]() ![]() |
|
|
Jan 28 2011, 08:08 AM
Post
#1
|
|
|
New Member Posts: 18 |
I hope anyone help me, how to create Login Form for multiple user in Access ?
thank |
|
|
|
Jan 28 2011, 08:51 AM
Post
#2
|
|
|
UtterAccess VIP Posts: 2,331 From: West Michigan |
If you are referring to the built-in security in Access 2003 and before, you should read the Microsoft Secuity FAQ.
The built-in security is no longer available in Access 2007 format databases (accdb), in which case, you'd need to build your own. Try these links: http://www.databasedev.co.UK/login.html http://www.access.qbuilt.com/html/custom_login.html These should get you started. |
|
|
|
Jan 28 2011, 09:29 AM
Post
#3
|
|
|
UtterAccess Veteran Posts: 455 From: Birmingham, Alabama |
If you're using 2007+, here is a link to a wiki article on the subject. Click Here
There are also several examples of different methods for creating user logins here in the forums that may be found by performing a search. Hope that helps. |
|
|
|
Jan 28 2011, 10:47 PM
Post
#4
|
|
|
New Member Posts: 18 |
I tried copy VB codes for login form from http://www.databased...o.UK/login.html :
Private Sub cmdLogin_Click() 'Check to see if data is entered into the UserName combo box If IsNull(Me.cboEmployee) Or Me.cboEmployee = "" Then MsgBox "You must enter a User Name.", vbOKOnly, "Required Data" Me.cboEmployee.SetFocus Exit Sub End If 'Check to see if data is entered into the password box If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then MsgBox "You must enter a Password.", vbOKOnly, "Required Data" Me.txtPassword.SetFocus Exit Sub End If 'Check value of password in tblEmployees to see if this 'matches value chosen in combo box If Me.txtPassword.Value = DLookup("strEmpPassword", "tblEmployees", _ "[lngEmpID]=" & Me.cboEmployee.Value) Then lngMyEmpID = Me.cboEmployee.Value 'Close logon form and open splash screen DoCmd.Close acForm, "frmLogon", acSaveNo DoCmd.OpenForm "frmSplash_Screen" 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 admin.", _ vbCritical, "Restricted Access!" Application.Quit End If End Sub I found error "Can't find project or library" for "lngMyEmpID", and I was tried to replace this code with "lngEmpID" by delete of "My", but still error if I run in Microsoft Access XP, but while I run in Access 2010, it working properly, my file Access saved as Access 2000. Can anyone help me, pls Thank |
|
|
|
Jan 29 2011, 06:17 PM
Post
#5
|
|
|
UtterAccess Veteran Posts: 330 |
Hi.
1st. Create two unbound text boxes. 1. Username 2. Password 2nd. Create two buttons: 1. cmdOK 2. cmdCancel 3th. Add this code to OnClick [Event Procedure] CODE Private Sub cmdOK_Click() Dim rs As Recordset Dim strSQL As String Dim strPassword As String Dim strUserName As String On Error Resume Next strUserName = Username.Value strPassword = Password.Value Set db = CurrentDb strSQL = "SELECT password FROM sUser WHERE username='" & strUserName & "'" Set rs = db.OpenRecordset(strSQL) If rs.RecordCount > 0 Then If rs.Fields(0) <> strPassword Then msgbox "You typed wrong username or password. Try again.", vbOKOnly, "Warning!" Else Me.Visible = False DoCmd.OpenForm "FORM NAME OR SWITCHBOARD", acNormal, , , , acDialog End If Else msgbox "You typed wrong username or password. Try again.", vbOKCancel, "Warning!" Username.SetFocus End If End Sub 4th. Add to General Decralations CODE Public strUserName As String 5th. Add on Form_OnLoad: CODE Private Sub Form_Load() Username.SetFocus Username.Value = "" Password.Value = "" End Sub Put some nice background with key picture and enjoy. (IMG:style_emoticons/default/smile.gif) This post has been edited by Tiesto_X: Jan 29 2011, 06:18 PM |
|
|
|
Jan 30 2011, 02:58 AM
Post
#6
|
|
|
UtterAccess Veteran Posts: 330 |
Oh I forgot something.
6th. Create Table sUser 1. ID [Autonumber] 2. Username [Text] 3. Password [Text] Put some username and password. Thats it. |
|
|
|
Feb 1 2011, 06:16 AM
Post
#7
|
|
|
New Member Posts: 18 |
Ok, thank very much
|
|
|
|
May 17 2012, 10:17 AM
Post
#8
|
|
|
New Member Posts: 1 |
Hey man. thanks for the code. it is really helpful. but i have a problem. i kinda get what the code says. but i dont get the below parts. can u please explain it to me (What it means)
- what is a record set - what does "Set db = CurrentDb strSQL = "SELECT password FROM sUser WHERE username='" & strUserName & "'" Set rs = db.OpenRecordset(strSQL) If rs.RecordCount > 0 Then If rs.Fields(0) <> strPassword" this mean? - what does rs.fields(0) mean Thanks you in advance (IMG:style_emoticons/default/thanks.gif) and could u reply ASAP This post has been edited by Miduhath: May 17 2012, 10:18 AM |
|
|
|
![]() ![]() |
|
Go to Top · Lo-Fi Version | Time is now: 20th May 2013 - 04:06 AM |