473,775 Members | 2,335 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

19 New Member
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 3708
Scott Price
1,384 Recognized Expert Top Contributor
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 Recognized Expert Top Contributor
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 New Member
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 Recognized Expert Top Contributor
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 Recognized Expert Top Contributor
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
6057
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 self calling script (ASP, PHP, whatever) which will do the following: Let's assume that my script is called FTP.ASP 1) Display an HTML login form prompting user to enter a user name and password. Login button action (either at the button or...
1
13071
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 start over or load the main file.... I attempted to use a slect case..but its not working for me.. If someone has a better way of doing it..I would apperciate the help. Thank you! Option Explicit Public LoginSucceeded As Boolean
7
2360
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 WinForms interface and then need to port that to a web app. I am kinda stuck on a design issue and need some suggestions / direction. Basically I have a business layer that I want to use to process any dataentry logic (row focus changes, data...
4
2336
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 unauthenticated user is browsing the site, and tries to open the UltraSecretContent.aspx page. Forms authentication automatically redirects the user to login.aspx. I would like for login.aspx to display a message that reads, "You must log in before viewing...
3
2326
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 redirects. But first it doesn't tell you that you're logged in and doesn't provide a logout feature. And most importantly if I type in a random username and password not listed in the database it doesn't seem to matter it still "lets me login"
20
3195
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 when the User click on the Close Button of Browser ? I am using Sql Membership Provider for security. Best Regards,
3
3643
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 password. The current VBA performs all the relevant checks around user name & password etc with no problems. However based on the users access level (which is set in the field "strAccess" in the Enployees table) when I click the "Login" button I'd like to...
1
7113
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 someone who bothers to read all of it have some pointers. Note, I have posted the stack trace and the code exhibiting the problem further down so if you want to start by reading that, search for +++ Also note that I am unable to reproduce...
8
6265
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 "test" Please show me how to do it Thanks in advance I had code below
0
9621
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10267
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8939
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7463
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5358
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4014
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3611
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.