Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2004
    Posts
    6

    Question Unanswered: password protection with access levels using VBA

    FORM:
    ------------------------------------------------------------

    Please select your username: Admin(drop down box)
    Admin 2
    Admin 3

    Password: (type password here)

    Click to enter Enter button

    ------------------------------------------------------------
    This form works off a table Table Employees which has the fields

    TABLE:
    ------------------------------------------------------------
    ID Employee Name Password Access
    1 Joe ***** Admin
    2 John **** User

    ------------------------------------------------------------

    What we are trying to do is to have a command button 'Log On' on the main switchboard. When clicked this command button will bring up the form above, when the person finishes entering the information they clicked the command button which searches table employees and grants them the specific level of access eg.

    three levels of access
    admin - total access, can grant access
    level 2 - access where person has access over selected forms/tables/update/insert
    level 3 - you can view/print / not edit

    what we are trying to get done now is the VBA code needed to grant the specific levels of access to the respective user.

    The code we have so far for the command button on the form is:

    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 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"

    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
    ------------------------------------------------------------



    three levels of access
    admin - total
    level 2 - can grant access where person has access over selected forms/tables/update/insert
    level 3 - you can view/print / not edit

    command button on form with switchboard

  2. #2
    Join Date
    Oct 2003
    Location
    US
    Posts
    343
    Try using the Tag property of controls. Then as per security level you can hide/unhide controls. Thus you can control security over objects.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •