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

Making simple login window 'dynamic'

P: 5
Hello there, I am doing a school project and we haven't been taught lots of VBA.
To earn more marks, I copied this example (it's allowed-research) from databasedev.co.uk and I want to make the 'admin' to see a different form from the 'limited user'

You can download it from http://databasedev.co.uk/downloads/login.zip

I would appreciate the help.

Thanks in advance.

Here is the VBA code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdLogin_Click()
  2.  
  3. 'Check to see if data is entered into the UserName combo box
  4.  
  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
  10.  
  11. 'Check to see if data is entered into the password box
  12.  
  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
  18.  
  19. 'Check value of password in tblEmployees to see if this matches value chosen in combo box
  20.  
  21.     If Me.txtPassword.Value = DLookup("strEmpPassword", "tblEmployees", "[EmpID]=" & Me.cboEmployee.Value) Then
  22.  
  23.         lngMyEmpID = Me.cboEmployee.Value
  24.  
  25. 'Close logon form and open splash screen
  26.  
  27.         DoCmd.Close acForm, "frmLoginForm", acSaveNo
  28.         DoCmd.OpenForm "frmSelectLevelSwitch"
  29.  
  30.         Else
  31.         MsgBox "Password Invalid.  Please Try Again", vbOKOnly, "Invalid Entry!"
  32.         Me.txtPassword.SetFocus
  33.     End If
  34.  
  35. 'If User Enters incorrect password 3 times database will shutdown
  36.  
  37.     intLogonAttempts = intLogonAttempts + 1
  38.     If intLogonAttempts > 3 Then
  39.         MsgBox "You do not have access to this database.  Please contact your system administrator.", vbCritical, "Restricted Access!"
  40.         Application.Quit
  41.     End If
  42.  
  43. End Sub
Sep 13 '08 #1
Share this Question
Share on Google+
2 Replies


nico5038
Expert 2.5K+
P: 3,072
We don't do school projects, but I can give directions.
You'll need to add a test for "admin" in the code before opening a different form.
For getting the "admin marker" from the usertable you can use a DLookup like:
DLookup("IsAdmin", "tblEmployees", "[EmpID]=" & Me.cboEmployee.Value)

Success !

Nic;o)
Sep 13 '08 #2

P: 5
Thanks Nico. I'll give it a try
Sep 14 '08 #3

Post your reply

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