Results 1 to 7 of 7
  1. #1
    3 Star Lounger
    Join Date
    Feb 2004
    Location
    Kitchener, Ontario, Canada
    Posts
    228
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have a database being used by quite a few people. What I am wondering if it is possable is to set up a table with certian peoples NT login names. then set some of the forms so that only those NT Login Names listed in the table can open the form otherwise they get a access not allowed screen. Is this possable?

    I have added a sample database to help explain.... lets say 2 people try to open the form "Only OpsMgt can open form" the 2 users are mshaw and tdickson the results I want them to see is

    mshaw: he is listed in the table "OpsMgt" so the form :Only OpsMgt can open form" should open

    tdickson: he is not listed in the table "OpsMgt" so he should be redirected to the form " Generic not allowed form" and the form he tried to open should not.
    Attached Files Attached Files

  2. #2
    5 Star Lounger AndrewKKWalker's Avatar
    Join Date
    Apr 2001
    Location
    Cambridge, UK
    Posts
    1,020
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Unless you have people using Windows 98, you can use the Function

    Environ("USERNAME") (Typed exactly as it is there), to return the logged on user from the NT UserName

    Then you can reference that in a table.
    You can also do it with a windows API call, but Environ does the job more easily
    Andrew

  3. #3
    3 Star Lounger
    Join Date
    Feb 2004
    Location
    Kitchener, Ontario, Canada
    Posts
    228
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Andrew W View Post
    Then you can reference that in a table.
    I am still a little lost.

  4. #4
    5 Star Lounger AndrewKKWalker's Avatar
    Join Date
    Apr 2001
    Location
    Cambridge, UK
    Posts
    1,020
    Thanks
    0
    Thanked 3 Times in 3 Posts
    OK.

    You cannot do this without some VBA code to do the testing and switch forms.
    You could put this as part of the initial database startup so that the login determines which form opens,
    but this would involve having an autoexec macro pointing to running the code in a module.
    Since I do not know at which point you want this testing to take place, I have simply added an example of the type of code,
    in the On Open Event of the Management Only Form.
    This gets the Login details from Windows, Compares it to the table.
    If all is OK then it lets the form stay open. If not it cancels the open and opens the other form with a message.

    The code is as below in the attached database

    Code:
    Private Sub Form_Open(Cancel As Integer)
    
    'This code Checks for the logged on user Name
    'In the table OpsMgt
    'If it is found then nothing happens,otherwise it closes this form and opens the other form
    
    Dim strFormName As String
    Dim strUserName As String
    
    'Get Details
    strFormName = Me.Name
    strUserName = Environ("USERNAME")
    
    'Test if User Name in OpsMgt Table
    If DLookup("[NT Login Name]", "OpsMgt", "[NT Login Name]='" & strUserName & "'") & "" = "" Then
        'If Not Found then msgbox and open the other form (you don't have to have the message box)
        'Do Not Open this form
        Cancel = True
        'Send User a Message
        MsgBox "You do not have authorisation on the Management Form" & vbLf & "Being directed to User Form", vbExclamation
        'Then Open the other form
        DoCmd.OpenForm "Generic not allowed form"
    End If
    
    End Sub
    [attachment=89461:To Show_Updated.zip]
    Attached Files Attached Files
    Andrew

  5. #5
    3 Star Lounger
    Join Date
    Feb 2004
    Location
    Kitchener, Ontario, Canada
    Posts
    228
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Andrew W View Post
    & "" = ""

    That is the only part I really did not understand.. I was playing around with a if-then statment this weekend but I was messing up the first dlookup line.


    also what is the differance between the "on load" and "on open" I was trying it in the "on load"

  6. #6
    5 Star Lounger AndrewKKWalker's Avatar
    Join Date
    Apr 2001
    Location
    Cambridge, UK
    Posts
    1,020
    Thanks
    0
    Thanked 3 Times in 3 Posts
    The Form is First Opened and then the Data is Loaded into the form.
    You cannot CANCEL the Load Event, but you can cancel the Open Event


    See here for more info

    I think you are going to need to go and do some Reading up in order to get this database up and running.
    But it will be a good learning process.
    Andrew

  7. #7
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    I don't like users to see a message saying "You can't do that" or "You don't have permission to look at this."

    So if I don't want a group of users to be able to do something I always hide the command button that does that job.

    So I perform a test to see if they should do something or not, then set the visible property of the relevant controls to false, if I don't want them to do it.
    Regards
    John



Posting Permissions

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