473,327 Members | 2,071 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,327 software developers and data experts.

Trying to create login form which will open specific form depending on user

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:

Expand|Select|Wrap|Line Numbers
  1. Public Sub Login()
  2.  
  3. On Error GoTo ErrorHandler:
  4.  
  5.     If IsNull([cboUser]) = True Then 'Checks username entered
  6.         MsgBox "Username is required"
  7.  
  8.     ElseIf IsNull([txtPassword]) = True Then 'Checks validity of password entered
  9.         MsgBox "Password is required"
  10.  
  11.     Else
  12.  
  13.         'Compare password entered w/ password saved in table of users
  14.         If Me.txtPassword.Value = DLookup("Password", "tblUsers", "[UserName]='" & Me.cboUser.Value & "'") Then
  15.             strUser = Me.cboUser.Value 'Set the value of strUser declared as Global Variable
  16.             strRole = DLookup("Role", "tblUsers", "[UserName]='" & Me.cboUser.Value & "'") 
  17.             DoCmd.Close acForm, "frmLogin", acSaveNo
  18.             MsgBox "Welcome Back, " & strUser, vbOKOnly, "Welcome"
  19.             DoCmd.OpenForm "frmPersonnelOfficer", acNormal, "", "", , acNormal
  20.  
  21.         Else
  22.             MsgBox "Invalid Password. Please try again.", vbOKOnly, "Invalid Password"
  23.             intLogAttempt = intLogAttempt + 1
  24.             txtPassword.SetFocus
  25.  
  26.         End If
  27.  
  28.     End If
  29.  
  30.     'If user enters PW incorrectly three times
  31.     If intLogAttempt = 3 Then
  32.         MsgBox "You do not have access to this database.Please contact admin." & vbCrLf & vbCrLf & _
  33.         "Application will exit.", vbCritical, "Restricted Access!"
  34.         Application.Quit
  35.     End If
  36.  
  37. ErrorHandler:
  38.  
  39. End Sub
  40.  
  41.  
  42.  
  43.  



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.
Jan 12 '15 #1

✓ answered by jforbes

You can do something like the following for line 19:
Expand|Select|Wrap|Line Numbers
  1.     Select Case strRole
  2.         Case "Nurse"
  3.             sForm = "frmPersonnelOfficer"
  4.         Case "Doctor"
  5.             sForm = "frmPersonnelOfficer2"
  6.         Case Else
  7.     End Select
  8.     DoCmd.OpenForm sForm, acNormal, "", "", , acNormal

3 5259
jforbes
1,107 Expert 1GB
You can do something like the following for line 19:
Expand|Select|Wrap|Line Numbers
  1.     Select Case strRole
  2.         Case "Nurse"
  3.             sForm = "frmPersonnelOfficer"
  4.         Case "Doctor"
  5.             sForm = "frmPersonnelOfficer2"
  6.         Case Else
  7.     End Select
  8.     DoCmd.OpenForm sForm, acNormal, "", "", , acNormal
Jan 13 '15 #2
Thanks for posting that. It's helped me a lot.
Jan 13 '15 #3
twinnyfo
3,653 Expert Mod 2GB
Kondratiev,

You may also want to look at this article, as it may provide additional options for you:

MS Access User Permissions
Jan 21 '15 #4

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

Similar topics

1
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....
2
by: Zlatko Matić | last post by:
Hi. How to check whether some form is open or not, in VBA ? Thanks.
6
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...
7
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...
5
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...
7
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.
1
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...
13
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"...
2
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...
0
isladogs
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...
1
isladogs
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...
0
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...
0
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...
0
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...
1
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)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
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...
0
isladogs
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...

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.