• accessing forms using NT Login

    Author
    Topic
    #470672

    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.

    Viewing 3 reply threads
    Author
    Replies
    • #1236861

      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

    • #1236882

      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
      
      • #1237241

        & “” = “”

        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”

    • #1237244

      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.

    • #1237415

      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.

    Viewing 3 reply threads
    Reply To: accessing forms using NT Login

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: