Hello,
I am trying to create a user login form for an Access database. It will have three users and will open a different form depending on which user logs in to the database. So far I have only been able to create code which opens a single form no matter which user logs in. The code below shows the code I have made to accomplish this: - Public Sub Login()
-
-
On Error GoTo ErrorHandler:
-
-
If IsNull([cboUser]) = True Then 'Checks username entered
-
MsgBox "Username is required"
-
-
ElseIf IsNull([txtPassword]) = True Then 'Checks validity of password entered
-
MsgBox "Password is required"
-
-
Else
-
-
'Compare password entered w/ password saved in table of users
-
If Me.txtPassword.Value = DLookup("Password", "tblUsers", "[UserName]='" & Me.cboUser.Value & "'") Then
-
strUser = Me.cboUser.Value 'Set the value of strUser declared as Global Variable
-
strRole = DLookup("Role", "tblUsers", "[UserName]='" & Me.cboUser.Value & "'")
-
DoCmd.Close acForm, "frmLogin", acSaveNo
-
MsgBox "Welcome Back, " & strUser, vbOKOnly, "Welcome"
-
DoCmd.OpenForm "frmPersonnelOfficer", acNormal, "", "", , acNormal
-
-
Else
-
MsgBox "Invalid Password. Please try again.", vbOKOnly, "Invalid Password"
-
intLogAttempt = intLogAttempt + 1
-
txtPassword.SetFocus
-
-
End If
-
-
End If
-
-
'If user enters PW incorrectly three times
-
If intLogAttempt = 3 Then
-
MsgBox "You do not have access to this database.Please contact admin." & vbCrLf & vbCrLf & _
-
"Application will exit.", vbCritical, "Restricted Access!"
-
Application.Quit
-
End If
-
-
ErrorHandler:
-
-
End Sub
-
-
-
-
I would like to know what I would need to add to this so that a specific form would open for each user depending on the role which the user is assigned. For example, and admin user would open an admin form upon entering their password while a nurse user would see a nurse form having successfully entered their password.
Any help is appreciated.
You can do something like the following for line 19: - Select Case strRole
-
Case "Nurse"
-
sForm = "frmPersonnelOfficer"
-
Case "Doctor"
-
sForm = "frmPersonnelOfficer2"
-
Case Else
-
End Select
-
DoCmd.OpenForm sForm, acNormal, "", "", , acNormal
3 5259
You can do something like the following for line 19: - Select Case strRole
-
Case "Nurse"
-
sForm = "frmPersonnelOfficer"
-
Case "Doctor"
-
sForm = "frmPersonnelOfficer2"
-
Case Else
-
End Select
-
DoCmd.OpenForm sForm, acNormal, "", "", , acNormal
Thanks for posting that. It's helped me a lot.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Bob Sanderson |
last post by:
I have two forms, frmSearch and frmMain. I want to be able to enter a job
number in a text box on frmSearch and when I enter it, open frmMain and go
to the record for the job number I've entered....
|
by: Zlatko Matić |
last post by:
Hi.
How to check whether some form is open or not, in VBA ?
Thanks.
|
by: AppleBag |
last post by:
I'm having the worst time trying to login to myspace through code. Can
someone tell me how to do this? Please try it yourself before replying,
only because I have asked this a couple of times in...
|
by: Redbeard |
last post by:
Hi, I am newbie that is using Access 2003. I have a command button on a pop-up form that duplicates the current record displayed on my main form and all sub-forms attached to it. The last part of...
|
by: Mai Le |
last post by:
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...
|
by: mukeshrasm |
last post by:
hi
I want to create login window like youtube.com means when user clicks on Login a small screen get opened so what type of screen it is and how can I create it.
|
by: rakabuku |
last post by:
I'm really new with Acces and VBA, so all the help with code is greatly appreciated!
I created a form that kind of works like a switchboard (FRM_A) with two combo boxes . Both boxes take the...
|
by: cdoublen |
last post by:
Hi All
I'm very new to VB coding for Access. At present I'm doinga dbase which has a logon screen. Upon "User" or "Admin" logon I would like a relevant form be opened based on "User" or "Admin"...
|
by: rich1983 |
last post by:
Hi,
I have a VB.net project which consists of one main Form with about 5 buttons on.
When clicking on a button, this will open another Form using the button_click Sub. What I would like it to...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
| |