Solved

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

Posted on 2004-09-20
3
173 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

786 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