2 users - 1 login - 2 forms

  • Thread starter fapa via AccessMonster.com
  • Start date
F

fapa via AccessMonster.com

I've got a really simple question but i cant find the answer anywhere!

Ive just created a login form which checks the user's id and password to a
Login table. it works well however im not sure how to allow different users
to be directed to different pages. Eg. Admin is to be directed to Mangement
Switchboard when they type in their password and all the rest of the users
are to be directed to Staff Switchboard when they login.

here is the code i've writen so far (it directs everyone to the staff main
menu)



Private Sub cboEmployee_AfterUpdate()
'After selecting user name set focus to password field
Me.txtPassword.SetFocus
End Sub


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 Login Table to see if this
'matches value chosen in combo box

If Me.txtPassword.Value = DLookup("Password", "Login", "[UserID]=" & Me.
cboEmployee.Value) Then

UserID = Me.cboEmployee.Value

'Close login form and open Main Menu

DoCmd.Close acForm, "Login", acSaveNo
DoCmd.OpenForm "Staff Main Menu"

Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
Me.txtPassword.SetFocus
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 admin.",
vbCritical, "Restricted Access!"
Application.Quit
End If

End Sub


Also - i was hoping, and im not sure if this is possible - when management
enter another form which can be accessed by everyone, is there a way that
Management have 'management command buttons that directs them around the
system - without having these button's available to staff when a staff member
is logged in (p.s only one user can access the system at one time) p.s i hope
this question makes sense!
 
D

drahme

Hello, one way you can do this is to manipulate the switchboard form by
adding adding another field to the switchboard table and only display
the buttons the user needs to see.

In this example a field is added to the switchboard called security.
Each form and report is assigned a security level.

There is a login form prior to opening the switchboard like what you
describe. This information is passed to the switchboard form.

The switchboard has a text box added called txtSecurity
txtSecurity reads the user's security level when the switchboard opens
and the switchboard stSql is ajusted to that level.

stSql in the switchboard is replaced with something like this:

Select Case Me.txtSecurity

Case Is = 1 'Reports Only

stSql = "SELECT * FROM [Switchboard Items]"
stSql = stSql & " WHERE [ItemNumber] > 0 And [Startup] = -1 "
stSql = stSql & " AND [security] = 1 and [SwitchboardID]=" &
Me![SwitchboardID]
stSql = stSql & " ORDER BY [ItemNumber];"

Case Is = 4 'Users

stSql = "SELECT * FROM [Switchboard Items]"
stSql = stSql & " WHERE [ItemNumber] > 0 And [Startup] = -1 "
stSql = stSql & " AND [security] <= 4 and [SwitchboardID]=" &
Me![SwitchboardID]
stSql = stSql & " ORDER BY [ItemNumber];"

..... and so on.

It works quite well.

Hope that helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top