By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,080 Members | 1,276 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,080 IT Pros & Developers. It's quick & easy.

Access 2007 Login help

P: 10

I am new to Access and I have created a database for my company. I found code for a login script online. The code I used is as follows.
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdLogin_Click()
  3. 'Check to see if data is entered into the UserName combo box
  5.     If IsNull(Me.cboEmployee) Or Me.cboEmployee = "" Then
  6.       MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
  7.         Me.cboEmployee.SetFocus
  8.         Exit Sub
  9.     End If
  11.     'Check to see if data is entered into the password box
  13.     If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
  14.       MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
  15.         Me.txtPassword.SetFocus
  16.         Exit Sub
  17.     End If
  19.     'Check value of password in tblEmployees to see if this
  20.     'matches value chosen in combo box
  22.     If Me.txtPassword.Value = DLookup("strEmpPassword", "tblEmployees", _
  23.             "[lngEmpID]=" & Me.cboEmployee.Value) Then
  25.         lngMyEmpID = Me.cboEmployee.Value
  27.         'Close logon form and open splash screen
  29.         DoCmd.Close acForm, "frmLogon", acSaveNo
  30.         DoCmd.OpenForm "frmSplash_Screen"
  33.     Else
  34.       MsgBox "Password Invalid. Please Try Again", vbOKOnly, _
  35.             "Invalid Entry!"
  36.         Me.txtPassword.SetFocus
  37.     End If
  39.     'If User Enters incorrect password 3 times database will shutdown
  41.     intLogonAttempts = intLogonAttempts + 1
  42.     If intLogonAttempts > 3 Then
  43.       MsgBox "You do not have access to this database.Please contact admin.", _
  44.                vbCritical, "Restricted Access!"
  45.         Application.Quit
  46.     End If
  48. End Sub
I have created a Table called tblEmployees with the FIELDS of EmpID, EmpName, EmpPassword, and EmpUsertype. For the Usertype FIELD I inputted Admin or User for each person in the company. I need to have any user with Admin to be able to open a form that is specifically for admins, which I called frmSplash_Screen_Admin. Is there any way I could add to the existing code above? If not could anyone help me figure out how to do solve this issue?

Thank you.
Apr 15 '09 #1
Share this Question
Share on Google+
3 Replies

Expert Mod 15k+
P: 31,709
Your data doesn't seem to match the code at all. The field names are different. You need to go through the code first to make sure it matches your names for all the objects (fields etc).

When that's completed, in place of line #30 put the following lines :
Expand|Select|Wrap|Line Numbers
  1.         If DLookup("[EmpUserType]", _
  2.                    "[tblEmployees]", _
  3.                    "[EmpID]=" & Me.cboEmployee) = "Admin" Then
  5.             DoCmd.OpenForm "frmSplash_Screen_Admin"
  6.         Else
  7.             DoCmd.OpenForm "frmSplash_Screen"
  8.         End If
Welcome to Bytes!
Apr 15 '09 #2

P: 10
Hello NeoPa,

I actually didn't notice that I didn't match the Field names on the code with my tables. Your advice worked perfectly for me. Thank you very much.
Apr 15 '09 #3

Expert Mod 15k+
P: 31,709
Very pleased to hear it.

Good luck with your project.
Apr 15 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.