1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Development VB Access Logon Help

Discussion in 'Tech Support' started by jopers1986, 1 Jun 2010.

  1. jopers1986

    jopers1986 Member

    Joined:
    7 Jan 2005
    Posts:
    559
    Likes Received:
    4
    Hi all,

    Working on a little database for work, and want access control with different menu's for log ons.

    I've pinched some code which works nicely for password conrol, user names and passwords etc:

    Code:
     Private Sub Command4_Click()
    
    'Check to see if data is entered into the UserName combo box
    
        If IsNull(Me.Combo0) Or Me.Combo0 = "" Then
          MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
            Me.Combo0.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("logonPassword", "logon", _
                "[logonID]=" & Me.Combo0.Value) Then
    
            logonID = Me.Combo0.Value
    
            'Close logon form and open splash screen
    
            DoCmd.Close acForm, "logon", acSaveNo
            DoCmd.OpenForm "Line Diary"
                    
        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 admin.", _
                   vbCritical, "Restricted Access!"
            Application.Quit
        End If
    
    End Sub
    
    i have a log on table which has 3 fields

    logonID
    logonName
    logonPassword

    in this table i have 3 users

    "Admin" password - admin
    "User" password - user
    "ReadOnly" password - readonly

    what i'm after doing is having each user load open a different form when they log on:

    Admin to open "Admin Menu"
    User to open "Line Diary"
    ReadOnly to open "Read Menu"

    I'm tried playing around with nested if's in the code, but can't get anything to work...

    Can any one help? i'd REALLY appreciate it!!!

    Thanks

    Rich
     
  2. jopers1986

    jopers1986 Member

    Joined:
    7 Jan 2005
    Posts:
    559
    Likes Received:
    4
    Any one...? Please?
     
  3. Zoon

    Zoon Hunting Wabbits since the 80s

    Joined:
    12 Mar 2001
    Posts:
    5,337
    Likes Received:
    565
    Where you've got:
    Code:
    DoCmd.OpenForm "Line Diary"
    
    Put something like:
    Code:
    Select Case logonID
        Case "Admin"
    	DoCmd.OpenForm "Admin Menu"
        Case "User"
    	DoCmd.OpenForm "Line Diary"
        Case "ReadOnly"
    	DoCmd.OpenForm "Read Menu"
    End Select
    
     
  4. jopers1986

    jopers1986 Member

    Joined:
    7 Jan 2005
    Posts:
    559
    Likes Received:
    4
    hey, thanks for the reply, this gave me random outputs... admin wouldn't load anything, the other 2 both loaded line diary...

    i found this code which i moded and seems to work for me...

    Code:
    Option Compare Database
    
    Private Sub Combo0_AfterUpdate()
    'After selecting user name set focus to password field
        Me.txtPassword.SetFocus
    End Sub
    
    
    
    Private Sub Command4_Click()
      
      'Check to see if data is entered into the UserName combo box
    Dim lngMyEmpID As Long
    If IsNull(Me.Combo0) Or Me.Combo0 = "" Then
        MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
        Me.Combo0.SetFocus
        Exit Sub
    End If
    lngMyEmpID = Me.Combo0.Value
    '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 tblAdmins to see if this matches value chosen in combo box
      
    If Me.txtPassword.Value <> DLookup("logonPassword", "logon", "[logonID]=" & lngMyEmpID) Then
                MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
                Me.txtPassword.SetFocus
                Me.txtPassword = Null
                intLogonAttempts = intLogonAttempts + 1
                'If User Enters incorrect password 3 times database will shutdown
                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
      
    Else
        Me.txtPassword = Null
        'Open correct form
        Dim strAccessLevel As String
      
        strAccessLevel = DLookup("logonName", "logon", "[logonID]=" & lngMyEmpID)
      
        If strAccessLevel = "Admin" Then
            MsgBox "Welcome " & DLookup("logonName", "logon", "logonID=" & lngMyEmpID)
            DoCmd.Close
            DoCmd.OpenForm "Admin Menu"
        ElseIf strAccessLevel = "User" Then
            MsgBox "Welcome " & DLookup("logonName", "logon", "logonID=" & lngMyEmpID)
            DoCmd.Close
            DoCmd.OpenForm "Line Diary"
        ElseIf strAccessLevel = "ReadOnly" Then
            MsgBox "Welcome " & DLookup("logonName", "logon", "logonID=" & lngMyEmpID)
            DoCmd.Close
            DoCmd.OpenForm "Read Menu"
        End If
    End If
    
      
     End Sub
    
    my problem is now making a query to update/change the password....

    Cheers

    Rich
     
  5. Zoon

    Zoon Hunting Wabbits since the 80s

    Joined:
    12 Mar 2001
    Posts:
    5,337
    Likes Received:
    565
    Okay mate, what I gave you was strictly speaking something I'd use in aspx simply translated into vbScript so I'm not exactly shocked it wasn't perfect, but it at least seems to have pointed you in the right direction since the if...elseif...else is essentially the same as a Select Case :)
     
  6. jopers1986

    jopers1986 Member

    Joined:
    7 Jan 2005
    Posts:
    559
    Likes Received:
    4
    haha yeah it is cheers, just had to declare the access level string, i'm trying to develop it now, using this level as group access, then having users in each group... getting confusing, already made the mistake of not version controlling the database.....
    i've now do it to assign people to a group, and user the user name to log on, but i'm having trouble getting it to look at the user group for confirmation as well as the password...
    fun times...
     

Share This Page