Results 1 to 8 of 8
  1. #1
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727

    form open

    All, working on an access 2003 database. I have this logon form called “frmLogon”. I am trying not to use a main switchboard and have users go to the correct form based on their dept name after the login form. This is the code:


    Code:
    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 tblEmployee to see if this matches value chosen in combo box
        If Me.txtPassword.Value = DLookup("strEmpPassword", "tblEmployee", "[lngEmpID]=" & Me.cboEmployee.Value) Then
            lngMyEmpID = Me.cboEmployee.Value
    'Close logon form and open splash screen
            
            DoCmd.Close acForm, "frmLogon", acSaveNo
            'DoCmd.OpenForm "frmHelpAbout"
            Call Permission
            'Call InitSplash
            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 the admin.", vbCritical, "Restricted Access!"
            Application.Quit
        End If
        
    End Sub
    Code:
    Public Function Permissions() As String
    Dim strDept As String
    strDept = DLookup("Dept", "tblUsers", "strEmpName=" & Forms!frmLogon!cboEmployee)
    Select Case strDept
    Case " Dept 1"
         DoCmd.OpenForm "frmMenu-Dept1"
    Case " Dept2"
         DoCmd.OpenForm "frmMenu- Dept2"
    Case " Dept3"
         DoCmd.OpenForm "frmMenu- Dept3"
    Case " Dept4"
         DoCmd.OpenForm "frmMenu- Dept4"
    Case " Dept5"
         DoCmd.OpenForm "frmMenu- Dept5"
    Case Else
        MsgBox "Unable to determine Department please try again"
    End Select
    End Function
    I’m getting an error: “Can’t find the reference form frmLogon”. I thought I was referencing the form correct but don’t know why it doesn’t like my code. I looked of the dlookup code and my code seems like it correct. Can anyone help point out what’s wrong please. Thanks

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You're closing the login form before calling the function.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    Ok. I closed the form after calling the function. But now it gives me an error: Data type mismatch in criteria expression. When I break; it reference the cboEmployee=1??

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    In the first code you seem to be looking for an ID value from the combo, in the second a name. Which is it? I suspect the function should use the ID field.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    Got it. But now the logon form is closing but its not opening the other form. It's like its not call the function but I know it is because I got an error but corrected it.

  6. #6
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    got it. Thanks for all your help!!

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I just noticed the function is Permissions but you call Permission.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. If any form is open, do not open this one
    By danilogg in forum Forms
    Replies: 2
    Last Post: 03-13-2013, 12:16 PM
  2. Replies: 10
    Last Post: 06-13-2012, 05:57 AM
  3. Replies: 2
    Last Post: 05-11-2012, 11:52 AM
  4. Replies: 1
    Last Post: 05-03-2012, 02:25 PM
  5. Replies: 2
    Last Post: 02-26-2010, 08:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums