Solved

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

Posted on 2004-09-20
3
171 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
Comment Utility
uping to 400 points
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 400 total points
Comment Utility
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
Comment Utility
That was it!  You got it! Thank you so much for your help! Much appreciated!
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

771 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

10 Experts available now in Live!

Get 1:1 Help Now