Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

Switchboard question!

Discussion in 'Information Technology' started by JOM, Jul 28, 2006.

  1. JOM

    JOM
    Expand Collapse
    Guest

    I would like to enable and disable some of the buttons depending on access
    level one has. in my Employee table, I have the following fields EName,
    loginID, AccessLevel -- 1 grants all rights while 2 limits the rights ti what
    can be accessed. How will I code it so that if your loginID isnot in the
    database it provides the msgbox provided below and when one clicks ok, it
    should exit.
    So on my switchboard in the open event procedure, I have the following
    Private Sub Form_Open(Cancel As Integer)
    ' Minimize the database window and initialize the form.

    ' Move to the switchboard page that is marked as the default.
    Me.Filter = "[ItemNumber] = 0 AND [Argument] = 'Default' "
    Me.FilterOn = True

    AL = DLookup("AccessLevel", "TblEmployee", "LoginID = '" &
    Environ("username") & "' ")

    If AL = 1 Then
    With Me
    .Option1.Enabled = True
    .Option2.Enabled = True
    .Option3.Enabled = True
    .Option4.Enabled = True
    End With

    ElseIf AL = 2 Then

    With Me
    .Option1.Enabled = True
    .Option2.Enabled = False
    .Option3.Enabled = False
    .Option4.Enabled = True
    End With
    Else
    If IsNull(AL) Then
    With Me
    .Option1.Enabled = True
    .Option2.Enabled = False
    .Option3.Enabled = False
    .Option4.Enabled = False
    End With
    End If
    MsgBox "You do not have sufficient access to use this database/application" _
    & Chr(13) & "See management", vbCritical, "Insufficient Database Access"

    End If
    End Sub
     
  2. Loading...

    Similar Threads Forum Date
    Question About GGS Questions and Answers Aug 28, 2016
    Marriage And Discrimination Related Questions Blogs Mar 21, 2016
    Sikhi Questioning Faith Sikh Sikhi Sikhism Mar 3, 2016
    Entering into Sikhism: Questions on Reht Maryada. Blogs Oct 22, 2015
    A question about kes/hair? Blogs Oct 21, 2015

  3. Jeff Conrad

    Jeff Conrad
    Expand Collapse
    Guest

    "JOM" wrote in message:
    news:7BDCCF68-CC3E-46DC-8544-90FC3C8B4C4E@microsoft.com...

    > I would like to enable and disable some of the buttons depending on access
    > level one has. in my Employee table, I have the following fields EName,
    > loginID, AccessLevel -- 1 grants all rights while 2 limits the rights ti what
    > can be accessed. How will I code it so that if your loginID isnot in the
    > database it provides the msgbox provided below and when one clicks ok, it
    > should exit.
    > So on my switchboard in the open event procedure, I have the following


    Personally I would not use the Environ as that can be easily circumvented.
    I would recommend using this code to retrieve the Network User ID:

    http://www.mvps.org/access/api/api0008.htm

    So using that API call just add in a few more lines of code like so:

    If IsNull(DLookup("AccessLevel", "TblEmployee", "LoginID = '" & fOSUserName & "' ")) Then
    MsgBox "You do not have sufficient permissions to use this database/application" _
    & vbNewLine & vbNewLine & "Please see Management.", vbCritical + vbOKOnly, _
    "Insufficient Database Access"
    DoCmd.Quit
    Exit Sub
    Else
    AL = DLookup("AccessLevel", "TblEmployee", "LoginID = '" & fOSUserName & "' ")
    End If

    If you still want to use Environ then just replace that part.

    --
    Jeff Conrad
    Access Junkie - MVP
    http://home.bendbroadband.com/conradsystems/accessjunkie.html
    http://www.access.qbuilt.com/html/articles.html
     
  4. Ron2006

    Ron2006
    Expand Collapse
    Guest

    Watch out for a possible error situation.

    I attempted that same type of thing but I was making the buttons
    visible/not visible. I encountered the problem that when the FIRST
    button was invisible (the user did not have access to that button), the
    form would give me an error on opening because it was trying to set the
    focus to that button. Enabling may not give you that type of problem.
     

Share This Page