Results 1 to 6 of 6
  1. #1
    cuddles is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    98

    Slight problem with my user check information

    I have a main form with several buttons that take end-users to various other forms in the database. All forms are accessible and available to my users and admins except for 1. There is a button on the main page that is a data entry button. I coded the onclick event for this button but those that have just user access can still click the button and get to this area, however the data entry form is disabled. I really would like the button to be disabled for anyone without an admin level. Here is my code. Is there a way to alter it at all?

    mainform code
    Code:
    Private Sub Form_Load()
        Dim sPermit As String
        Dim iAccess As Integer
        Dim Ctl As Access.Control
        Me.txtUser = Environ("UserLogin")
          If IsNothing(Me.txtUser) Then
            sPermit = "ReadOnly"
        Else
            sPermit = UserSecurity(Me.txtUser)
            End If
     
        Select Case sPermit
            Case "User"
                iAccess = User
            Case "Admin"
                iAccess = Admin
            Case Else
                iAccess = ReadOnly
        End Select
        Me.txtLevel = iAccess
        Me.txtLevel.Requery
    End Sub
    Private Function UserSecurity(sUser As String)
      UserSecurity = DLookup("UserSecurity", "user", "UserLogin='" & Forms!switchboard!txtUser & "'")
    End Function
    Private Sub txtLevel_Click()
     Dim sForm As String, sType As String
        sForm = Me.lstlevel.Column(1)
        sType = Me.lstlevel.Column(2)
        Select Case sType
            Case "Form"
                DoCmd.OpenForm sForm
            Case "Report"
                DoCmd.OpenReport sForm, acViewPreview
        End Select
    End Sub
    data entry form code

    Code:
    Private Sub Form_Load()
    If Forms!switchboard!txtLevel = User Then
       Me.AllowEdits = False
    Else
       Me.AllowEdits = True
    End If
    End Sub
    I can see now the problem is because the user level stuff is on the actual data entry form and needs to be associated with that button, however the button already has a click event to go to the data entry form. There is no way to do an on enter for the same command is there? or can I maybe put the if forms! statement into my main form somewhere? Or how about doing some sort of call function on my main form that looks at this code? Is that possible?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,622
    Environ("UserLogin") gives me nothing. I have never seen that before. I use Environ("USERNAME").

    Why don't you set the button not visible for non-admin users?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    cuddles is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    98
    So I should be using username, I can do that. But how do I change the on form load to make the button not visible?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,622
    At the end of load event, something like:

    Me.buttonname.Visible = (iAccess = "Admin")

    Or set the button Visible property to No and only make it visible if user is Admin. So under the Case "Admin", just:

    Me.buttonname.Visible = True
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    cuddles is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    98
    This works perfect:

    Code:
      
    Private Sub Form_Load()
        Dim sPermit As String
        Dim iAccess As String
        Dim Ctl As Access.Control
        Me.txtuser = Environ("username")
        If IsNothing(Me.txtuser) Then
            sPermit = "ReadOnly"
        Else
            sPermit = GetPermission(Me.txtuser)
        End If
        Select Case sPermit
            Case "Admin"
                iAccess = "Admin"
            Case Else
                iAccess = "User"
        End Select
        Me.txtLevel = iAccess
        Me.Requery
        Me.Command1.Visible = (iAccess = "Admin")
    End Sub
    Private Function GetPermission(sUser As String)
        If (IsNothing(DLookup("Permissions", "User", "UserLogin='" & Forms!Switchboard!txtuser & "'"))) Then
            GetPermission = "ReadOnly"
        Else
            GetPermission = DLookup("Permissions", "User", "UserLogin='" & Forms!Switchboard!txtuser & "'")
        End If
    End Function

  6. #6
    cuddles is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    98
    BTW, you saved me a ton of headache lengthy coding to simply hide 1 button on the main form. I read and read on user forms and user stuff and was simply thinking wow.................all that to hide 1 button?? Insane. I wanted something very simple because they want simplicity.

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

Similar Threads

  1. Get user information from AD.
    By UserInterface in forum Access
    Replies: 15
    Last Post: 06-03-2013, 08:27 PM
  2. how to get user information
    By rashima in forum Programming
    Replies: 5
    Last Post: 04-13-2012, 01:47 PM
  3. merging check box information into Word Docs
    By LeesKeys in forum Access
    Replies: 1
    Last Post: 10-19-2011, 03:37 PM
  4. slight number problem
    By Rigsby in forum Database Design
    Replies: 3
    Last Post: 01-06-2011, 11:27 AM
  5. Form Filter Causing slight problem
    By cowboy in forum Forms
    Replies: 3
    Last Post: 04-15-2010, 07:32 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