Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-09-20
3
Medium Priority
?
181 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 

Author Comment

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

Accepted Solution

by:
Carl Tawn earned 1600 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…
Suggested Courses

636 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