473,463 Members | 1,465 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Access Login Form problems

2
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 open 1 of 2 different forms, i.e "Admin" access level to open "Frontsheet" and "User" access level to open "frmAdvisorSummary", the trouble is I keep getting a "runtime error 2467" which points me to the following line of code "strAccessLevel = DLookup("[strAccess]", "tblEmployees", "[strEmpName]=" & Me.cboEmployee.Value)"

The whole code is as follows, any help/advice would be greatfully recieved as I'm at a complete loss.
Hope this makes sense

Many Thanks
Stuart


Full Code is

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
End If
'Close logon form and open FrontSheet

DoCmd.Close acForm, "frmLogon", acSaveNo

'Open correct form
Dim strAccessLevel As String

strAccessLevel = DLookup("[strAccess]", "tblEmployees", "[strEmpName]=" & Me.cboEmployee.Value)

If strAccessLevel = "Admin" Then
DoCmd.OpenForm "Frontsheet"
Else
If strAccessLevel = "User" Then
DoCmd.OpenForm "frmAdvisorSummary"
Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
Me.txtPassword.SetFocus
Exit Sub
End If
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 your system administrator.", vbCritical, "Restricted Access!"
Application.Quit
End If
End Sub
Sep 6 '07 #1
3 3611
Scott Price
1,384 Expert 1GB
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", "[lngEmpID]=" & Me.cboEmployee.Value) Then
  22.  
  23. lngMyEmpID = Me.cboEmployee.Value
  24. End If
  25. 'Close logon form and open FrontSheet
  26.  
  27. DoCmd.Close acForm, "frmLogon", acSaveNo
  28.  
  29. 'Open correct form
  30. Dim strAccessLevel As String
  31.  
  32. strAccessLevel = DLookup("[strAccess]", "tblEmployees", "[strEmpName]=" & Me.cboEmployee.Value)
  33.  
  34. If strAccessLevel = "Admin" Then
  35. DoCmd.OpenForm "Frontsheet"
  36. Else
  37. If strAccessLevel = "User" Then
  38. DoCmd.OpenForm "frmAdvisorSummary"
  39. Else
  40. MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
  41. Me.txtPassword.SetFocus
  42. Exit Sub
  43. End If
  44. End If
  45.  
  46. 'If User Enters incorrect password 3 times database will shutdown
  47.  
  48. intLogonAttempts = intLogonAttempts + 1
  49. If intLogonAttempts > 3 Then
  50. MsgBox "You do not have access to this database. Please contact your system administrator.", vbCritical, "Restricted Access!"
  51. Application.Quit
  52. End If
  53. End Sub
It looks to me like you are referencing an employees ID# in line 21 to the Me.cboEmployee.Value, but in line 32 you are referencing the employees' name to the same value. Change line 32 to reference the ID, and it should work.

Regards,
Scott
Sep 8 '07 #2
stumo
2
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", "[lngEmpID]=" & Me.cboEmployee.Value) Then
  22.  
  23. lngMyEmpID = Me.cboEmployee.Value
  24. End If
  25. 'Close logon form and open FrontSheet
  26.  
  27. DoCmd.Close acForm, "frmLogon", acSaveNo
  28.  
  29. 'Open correct form
  30. Dim strAccessLevel As String
  31.  
  32. strAccessLevel = DLookup("[strAccess]", "tblEmployees", "[strEmpName]=" & Me.cboEmployee.Value)
  33.  
  34. If strAccessLevel = "Admin" Then
  35. DoCmd.OpenForm "Frontsheet"
  36. Else
  37. If strAccessLevel = "User" Then
  38. DoCmd.OpenForm "frmAdvisorSummary"
  39. Else
  40. MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
  41. Me.txtPassword.SetFocus
  42. Exit Sub
  43. End If
  44. End If
  45.  
  46. 'If User Enters incorrect password 3 times database will shutdown
  47.  
  48. intLogonAttempts = intLogonAttempts + 1
  49. If intLogonAttempts > 3 Then
  50. MsgBox "You do not have access to this database. Please contact your system administrator.", vbCritical, "Restricted Access!"
  51. Application.Quit
  52. End If
  53. End Sub
It looks to me like you are referencing an employees ID# in line 21 to the Me.cboEmployee.Value, but in line 32 you are referencing the employees' name to the same value. Change line 32 to reference the ID, and it should work.

Regards,
Scott
Thanks Scott That's really helplfull. much appreciated

Regards
Stuart
Sep 20 '07 #3
Scott Price
1,384 Expert 1GB
Thanks Scott That's really helplfull. much appreciated

Regards
Stuart
Glad it worked for you!

Regards,
Scott
Sep 20 '07 #4

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

Similar topics

3
by: Paul | last post by:
Hi all, at present I I've built a website which can be updated by admin and users. My problem, I've combined "log in" and "access levels" to restrict access to certain pages, using the built...
4
by: Alex | last post by:
Dear netters, We are looking to build a SQL Server database that will be hooked up to a Web server (WebLogic or a .NET). The database will house data for multiple customers, and the...
3
by: Siobhan Perricone | last post by:
I have a user who is having a problem with an access database that I didn't build and haven't had anything to do with in the past. The database opens up to the switchboard, and she clicks through...
6
by: cyndithomas via AccessMonster.com | last post by:
I new to Visual Basic and am struck on a issue. Have created a Login in Screen for Remote User to access and input data. Want the Remote to be able to login & access the Input Form, and Manager...
16
by: Ben Sehara | last post by:
Is there any way I can limit the access to my website? I have a site "A" and I want to allow access to it only from site "B" login user. If someone try to access site "A" directory, I want it...
0
by: kang jia | last post by:
hi i have small problems occurred in my login function, which i use Django to build, in my template which is login.html, the code is like the following: <html> <head>...
3
by: Earl Anderson | last post by:
One of the users in our departmental db has Read/Write permissions to a particular form. He was able to access and edit the form at will until 2 weeks ago. His current problem was that he was not...
1
by: webandwe | last post by:
Hi, Can somebody please show me how to change the connection so I can make it work with my MYSQL database... I just need this login to work then I'm done wiht my project. I don't know what is...
10
by: DavidPr | last post by:
When I logout as one user and log in under a different user, it opens with the last user's information. User 1 - Unsername: Davey Jones User 2 - Unsername: David Smith I log out from Davey...
0
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...
0
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
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 ...

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.