Solved

VB Question MS Access. Trying to direct Users to individial forms

Posted on 2004-09-20
3
172 Views
Last Modified: 2010-05-02
I am using the following to bring up a form that prompts for a user name from a drop down list and then checks it against a database. There are three user names only. Depending on which user logs in I want it to go to a different Form.
Let me know how:

Option Compare Database
Private intLogonAttempts As Integer

Private Sub Form_Open(Cancel As Integer)
'On open set focus to combo box
Me.cboEmployee.SetFocus
End Sub

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 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
         
         
'Close logon form and open splash screen
               
        DoCmd.Close acForm, "frmLogon", acSaveNo
        DoCmd.OpenForm "Switchboard Forum"

        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 your system administrator.", vbCritical, "Restricted Access!"
        Application.Quit
    End If
   
End Sub
Private Sub Quit_Click()
On Error GoTo Err_Quit_Click


    DoCmd.Quit

Exit_Quit_Click:
    Exit Sub

Err_Quit_Click:
    MsgBox Err.Description
    Resume Exit_Quit_Click
   
End Sub
0
Comment
Question by:elliotth123
  • 2
3 Comments
 

Author Comment

by:elliotth123
ID: 12105159
uping to 400 points
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 400 total points
ID: 12105516
Assuming that the line:

    lngMyEmpID = Me.cboEmployee.Value

Sets the ID of the logged in user, then you simply need to use an If statement or a Select Case to redirect appropriatley. Something like:

   Select Case lngMyEmpID

      Case 1
          Form1.Show

      Case 2
         Form2.Show

      Case 3
         Form3.Show

   End Select

Where you put this code depends on how you want your app to behave.

Hope this helps.
0
 

Author Comment

by:elliotth123
ID: 12105815
That was it!  You got it! Thank you so much for your help! Much appreciated!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now