none
Restricting a field update to just specific users RRS feed

  • Question

  • I am trying to find an easy (if that is possible) solution. I have a database that when a user logs in, a global variable is created so that when changes are made to a record the updated information is appended to a log table.  It collects the change to the variable and pulls in the user from the global variable. I have a field in the database that would be best served if only two different users could update this specific field. Is there a way to use the global variable to determine if the correct user is logged in and then just allow them to make an update to the field? I would assume the record would be locked to editing unless one of the two users were logged in.

    I hope this makes sense.  If anyone has any suggestions on how to write the code for this, I would really appreciate it.

    Thursday, December 21, 2017 3:50 PM

Answers

  • If LogInUser = "Lisa Robinson" Or "Mary McQuade" Then
        Me.Extension_Approved.Locked = False
        Else
        Me.Extension_Approved.Locked = True
    End If

    Hi seebert,

    An alternative to if-then-else could be:

    Select Case LogInUser
    Case "Lisa Robinson", "Mary McQuade"
        Me.Extension_Approved.Locked = False
    Case Else
        Me.Extension_Approved.Locked = True
    End Select

    Imb.

    • Proposed as answer by Chenchen LiModerator Friday, December 22, 2017 5:45 AM
    • Marked as answer by seebert Friday, December 22, 2017 1:20 PM
    Thursday, December 21, 2017 9:29 PM

All replies

  • Hi,

    I am not sure I see a problem. For example, if Joe logs in and the variable is set to the value "Joe," then when the field is updated, you can check if the value of the variable is set to "Joe" before allowing the change. If Jeff logs in, which changes the variable's value to "Jeff," then your code, which is checking for the value "Joe" will not allow any changes to the field.

    Is that what you're asking? 

    Thursday, December 21, 2017 4:18 PM
  • That is exactly what I am trying to do - I just don't know who to write the code to check if Joe has logged in so that the field is open to be edited by him.
    Thursday, December 21, 2017 4:28 PM
  • Hi,

    So, how is the variable being updated now? Can you show us the code for it? If you want to check the value of the variable, you could just use an If statement. For example:

    If VariableName = "Joe" Then

    ...

    Hope it helps...

    Thursday, December 21, 2017 4:37 PM
  • I have a field in the database that would be best served if only two different users could update this specific field.

    Hi seebert,

    Also, you could set the locked property of that specific field default to True. When the authorized person opens the form. the locked property can be set to False in the Open or Load event. Of course I have assumed that record editing is only done with a form, and not directly in the table.

    Imb.

    Thursday, December 21, 2017 5:06 PM
  • This is how I have the code written (on Form Current Event):

    If LogInUser = "Lisa Robinson" Or "Mary McQuade" Then
        Me.Extension_Approved.Locked = False
        Else
        Me.Extension_Approved.Locked = True
    End If

    I am getting an error when I try to run it. Any ideas?

    Thursday, December 21, 2017 7:19 PM
  • Hi,

    What was the error message? When you have two conditions to compare, you'll need to separate them. For example:

    If LogInUser = "Lisa Robinson" OR LogInUser = "Mary McQuade" Then

    Hope it helps...

    Thursday, December 21, 2017 8:10 PM
  • If LogInUser = "Lisa Robinson" Or "Mary McQuade" Then
        Me.Extension_Approved.Locked = False
        Else
        Me.Extension_Approved.Locked = True
    End If

    Hi seebert,

    An alternative to if-then-else could be:

    Select Case LogInUser
    Case "Lisa Robinson", "Mary McQuade"
        Me.Extension_Approved.Locked = False
    Case Else
        Me.Extension_Approved.Locked = True
    End Select

    Imb.

    • Proposed as answer by Chenchen LiModerator Friday, December 22, 2017 5:45 AM
    • Marked as answer by seebert Friday, December 22, 2017 1:20 PM
    Thursday, December 21, 2017 9:29 PM
  • See below example code I use in a Forms "On Open" event to make controls visible to specific network user ids.

    Private Sub Form_Open(Cancel As Integer)
    Dim myUser As String
    Dim myWsh As Object         'IWshRuntimeLibrary.WshNetwork
    
    Set myWsh = CreateObject("wscript.network")
    myUser = myWsh.UserName
    Select Case myUser
     Case "bmiller", "chernandez"
      Me.LblRcvFrom.Visible = True
      Me.cboRcvFrom.Visible = True
     Case Else
      Me.LblRcvFrom.Visible = False
      Me.cboRcvFrom.Visible = False
    End Select
    
    DoCmd.Maximize
    Set myWsh = Nothing
    
    End Sub


    If this post answered or helped you find the answer to your question, please mark it as such for other Forum users knowledge.


    Thursday, December 21, 2017 9:35 PM
  • This worked perfectly.  Thanks for the assistance!!
    Friday, December 22, 2017 1:20 PM