Results 1 to 8 of 8
  1. #1
    krc9127 is offline Novice
    Windows 11 Access 2007
    Join Date
    Jul 2023
    Posts
    26

    Username and Security Level

    Is there a better way to code this? I would like it to look and the username and then see what security level they are. If they are a 2 or 3 they have access otherwise access is denied. I would rather have a security value instead of putting actual names.

    This is assigned to the Logon Button:
    Private Sub LogonBtn_Click()
    Dim ID As Long, PW As String, SecurityLevel As String

    ID = Nz(DLookup("UserID", "UserT", "Username=""" & Username & """"), 0)
    If ID = 0 Then
    MsgBox "User not found"
    Quit
    End If

    PW = Nz(DLookup("Password", "UserT", "UserID=" & ID), "")
    If PW <> Password Then
    MsgBox "Incorrect Password"
    Quit
    End If

    TempVars("Username") = Username.Value
    DoCmd.OpenForm "MainMenuF"
    DoCmd.Close acForm, Me.Name, acSaveYes

    End Sub

    I have this on each report:
    If TempVars("Username") = "Ken" Or TempVars("Username") = "Staton" Or TempVars("Username") = "Kelly" Then
    DoCmd.OpenReport "CombinedRider-Special Chart", acViewReport
    Else


    MsgBox "Access Denied"
    End If

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    So lookup the SecurityLevel?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    krc9127 is offline Novice
    Windows 11 Access 2007
    Join Date
    Jul 2023
    Posts
    26
    That's the part I am not sure about. How to add it. How do I look it up from the username they input?

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Quote Originally Posted by krc9127 View Post
    That's the part I am not sure about. How to add it. How do I look it up from the username they input?
    The same way you look up the other data, it is just another field.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    krc9127 is offline Novice
    Windows 11 Access 2007
    Join Date
    Jul 2023
    Posts
    26
    Do I load it into a TempVars as well?

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Quote Originally Posted by krc9127 View Post
    Do I load it into a TempVars as well?
    Well I would, as you then have all 3 data items to hand and do not need to look them up all the time?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  7. #7
    krc9127 is offline Novice
    Windows 11 Access 2007
    Join Date
    Jul 2023
    Posts
    26
    So like this:

    SL = Nz(DLookup("Username", "UserT", "SecurityLevel=""" & SecurityLevel & """"), 0)
    TempVars("SecurityLevel") = SecurityLevel.Value

  8. #8
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    No
    That is looking up username?
    If you do not know the syntax, google the function.
    Do not just make stuff up, coding does not work like that.

    Think about it, you are using security level as criteria. The one thing you are trying to find?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

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

Similar Threads

  1. Need help with security level coding
    By omnivox84 in forum Programming
    Replies: 13
    Last Post: 10-15-2015, 04:36 AM
  2. Form Level Security
    By brispark in forum Sample Databases
    Replies: 2
    Last Post: 08-16-2014, 08:35 AM
  3. Form Level Security
    By Gina Maylone in forum Security
    Replies: 4
    Last Post: 12-18-2013, 01:21 PM
  4. User Level Security
    By A kinason in forum Sample Databases
    Replies: 6
    Last Post: 11-02-2013, 02:00 AM
  5. help with security level
    By nojtuag in forum Access
    Replies: 3
    Last Post: 10-19-2011, 01:27 PM

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