473,387 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Need Help !!! Login Level to Open different form.

19
Hello Experts.
Coul you please help me to fix my program.
I created a login from with 2 levels. Admin an User.
If Admin login will open A form
and If User login will open B form

I had table tblAdmins
EmpID
EmpName
EmpPassword
Access field for Admin and User Level

Here is the code
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdLogin_Click()
  2.   'Check to see if data is entered into the UserName combo box
  3.  
  4.   If IsNull(Me.cboEmployee) Or Me.cboEmployee = "" Then
  5.   MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
  6.   Me.cboEmployee.SetFocus
  7.   Exit Sub
  8.   End If
  9.  
  10.  'Check to see if data is entered into the password box
  11.  
  12.  If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
  13.  MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
  14.  Me.txtPassword.SetFocus
  15.  Exit Sub
  16.  End If
  17.  
  18.  'Check value of password in tblAdmins to see if this matches value chosen in combo box
  19.  
  20.  If Me.txtPassword.Value = DLookup("EmpPassword", "tblAdmins", "[EmpID]=" & Me.cboEmployee.Value) Then
  21.  
  22.  lngMyEmpID = Me.cboEmployee.Value
  23.  End If
  24.  
  25.  
  26.  'Open correct form
  27.  Dim strAccessLevel As String
  28.  
  29.  strAccessLevel = DLookup("[Access]", "tblAdmins", "[EmpID]=" & Me.cboEmployee.Value)
  30.  
  31.  If strAccessLevel = "Admin" Then
  32.  DoCmd.OpenForm "A"
  33.  Else
  34.  If strAccessLevel = "User" Then
  35.  DoCmd.OpenForm "B"
  36.  Else
  37.  MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
  38.  Me.txtPassword.SetFocus
  39.  Exit Sub
  40.  End If
  41.  End If
  42.  
  43.  'If User Enters incorrect password 3 times database will shutdown
  44.  
  45.  intLogonAttempts = intLogonAttempts + 1
  46.  If intLogonAttempts > 3 Then
  47.  MsgBox "You do not have access to this database. Please contact your system administrator.", vbCritical, "Restricted Access!"
  48.  Application.Quit
  49.  End If
  50.  End Sub
  51.  
I tried but could not. Please help.

Thanks in advance
Mar 29 '08 #1
5 3677
Scott Price
1,384 Expert 1GB
Mai Le,

Please do not double post. I have deleted your other thread relating to this same question but without the added code.

Please use the [code] tags provided by selecting your code text in this reply window and clicking the # icon on the menu bar of the reply window.

MODERATOR
Mar 29 '08 #2
Scott Price
1,384 Expert 1GB
What is the problem that you are facing with this code? You need to tell us what doesn't work.

Regards,
Scott
Mar 29 '08 #3
Mai Le
19
What is the problem that you are facing with this code? You need to tell us what doesn't work.

Regards,
Scott
Thanks for your support.
The code is working but somehow put any password in then can open form. another is password stays in password.
Please help again.
Thanks
Have a nice weekend.
Mar 29 '08 #4
Scott Price
1,384 Expert 1GB
Your code looks a little choppy. By this I mean that it doesn't flow correctly from one procedure to the next. Try this:

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. Dim lngMyEmpID As Long
  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. lngMyEmpID = Me.cboEmployee.Value
  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 tblAdmins to see if this matches value chosen in combo box
  20.  
  21. If Me.txtPassword.Value <> DLookup("EmpPassword", "tblAdmins", "[EmpID]=" & lngMyEmpID) Then
  22.             MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
  23.             Me.txtPassword.SetFocus
  24.             Me.txtPassword = Null
  25.             intLogonAttempts = intLogonAttempts + 1
  26.             'If User Enters incorrect password 3 times database will shutdown
  27.             If intLogonAttempts >= 3 Then
  28.                 MsgBox "You do not have access to this database. Please contact your system administrator.", vbCritical, "Restricted Access!"
  29.                 Application.Quit
  30.             End If
  31.  
  32. Else
  33.     Me.txtPassword = Null
  34.     'Open correct form
  35.     Dim strAccessLevel As String
  36.  
  37.     strAccessLevel = DLookup("[Admins]", "tblAdmins", "[EmpID]=" & lngMyEmpID)
  38.  
  39.     If strAccessLevel = "Admin" Then
  40.         MsgBox "Welcome " & DLookup("EmpName", "tblAdmins", "EmpID=" & lngMyEmpID)
  41.         DoCmd.Close
  42.         DoCmd.OpenForm "A"
  43.     ElseIf strAccessLevel = "User" Then
  44.         MsgBox "Welcome " & DLookup("EmpName", "tblAdmins", "EmpID=" & lngMyEmpID)
  45.         DoCmd.Close
  46.         DoCmd.OpenForm "B"
  47.     End If
  48. End If
  49.  
  50.  End Sub
Regards,
Scott
Mar 29 '08 #5
Scott Price
1,384 Expert 1GB
This thread is now closed because it is a duplicate of http://www.thescripts.com/forum/show...41#post3135141 .

I have not deleted this thread because it contains a potential code solution. For all further questions refer to the other thread.

MODERATOR
Mar 29 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Phillip Armitage | last post by:
I've spent the better part of two days checking out PHP, javascript and numerous other language sites trying to find what I figure should be be an easy web script page. Essentially what I want is a...
1
by: william cline | last post by:
Hi, I am a beginner and below I have code for a long in form. My goal is for the form to read a file of a list of users and thier passwords ....compare the text box inputs to the file and either...
7
by: Jack Addington | last post by:
I've got a fairly simple application implementation that over time is going to get a lot bigger. I'm really trying to implement it in a way that will facilitate the growth. I am first writing a...
4
by: David Krussow | last post by:
Just wondering if/how it would be possible to display a variable string on the login form - where the string varies depending on the form the user attempted to access. To clarify, an...
3
by: Jennifer.Berube | last post by:
okay...so I got this login script and I edited it all and it seems to run fine...IE it listens to the script as far as permissions go when I place a restriction on a page and when you login it...
20
by: luqman | last post by:
If user login with the login control in ASP.Net 2005 and then just close the browser and then open the browser again, the login status shows, User still Login? Any idea, how to Logout the User...
3
by: stumo | last post by:
Hi I'm fairly new to access and as such my experience of VBA is somewhat limited. I have a login form which is linked to an "employees table" which asks for users to enter their name and...
1
by: =?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?= | last post by:
I get the above error in some of the ASP.NET web applications on a server, and I need some help figuring out how to deal with it. This is a rather long post, and I hope I have enough details that...
8
by: Mai Le | last post by:
Hello, I used Microsoft Access to create a login form with Name Password Access Level Admin and User I would like to let Admin login and open MRB form and User login then open other form like...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.