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 "frmAdvisorSumm ary", the trouble is I keep getting a "runtime error 2467" which points me to the following line of code "strAccessL evel = DLookup("[strAccess]", "tblEmploye es", "[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.cboEm ployee) 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.txtPa ssword) 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("strEmp Password", "tblEmploye es", "[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]", "tblEmploye es", "[strEmpName]=" & Me.cboEmployee. Value)
If strAccessLevel = "Admin" Then
DoCmd.OpenForm "Frontsheet "
Else
If strAccessLevel = "User" Then
DoCmd.OpenForm "frmAdvisorSumm ary"
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
intLogonAttempt s = intLogonAttempt s + 1
If intLogonAttempt s > 3 Then
MsgBox "You do not have access to this database. Please contact your system administrator." , vbCritical, "Restricted Access!"
Application.Qui t
End If
End Sub
3 3644 - 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
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
- 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
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
Thanks Scott That's really helplfull. much appreciated
Regards
Stuart
Glad it worked for you!
Regards,
Scott
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 in "log in" and "user authentication,
restrict access to page" features. But I find the after login I constantly
get redirected from the restricted pages.
|
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
requirement is to have no customer see other customer data. Web server
will be responsible for authenticating users (ids and passwords will be
maintained there/possibly stored in the database, but will not be
actual database logins) -- and establishing...
|
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 to
the "look up by facility name" form, and opens it up. So far so good.
She is able to click on and view every single thing on this pretty
complicated form, including opening a variety of secondary forms.
However, whenever she clicks on the...
|
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 to Login to another screen to
view data.
Form 1 is rmFieldReq (Remote Users Form)
Form 2 is frmREquests (Manager Form)
Below is my Code
|
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 redirected to site
"B" for login. After login at site "B", you see the link to site"A". When
you click it, you see login page for site "A".
Is it possible?
Thanks.
| |
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>
<title>Login</title>
|
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 able to edit the data
(no message ever appeared telling him he could not change any data). The
only change to the db since he experienced the problem was that a new
version of the db was made available for installation which everyone has now...
|
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 going on here and is, this far from throughing my laptop into the wall.....
I want to change
cStr = "DRIVER={Microsoft Access Driver (*.mdb)};"
cStr = cStr & "DBQ=" & Server.MapPath("\path\to\database.mdb") & ";"
Conn.Open(cStr)
|
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 Jones, then login as David Smith the Welcome message below will show "Welcome Davey". And it will be Davey's information that is accessible - not David Smith's. So something is amiss but I don't know what.
(BTW, this login script is based on the...
|
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...
|
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...
| |
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...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |