How can I make the code below apply according to the record and not to the entire form? If i execute the code, it behaves according to the first record and does not change behavior if I change record.
For example,
Surname Username Allowedits
Johnson johnson25 TRUE
Smith johnson25 FALSE
The username is constant as a result of the PC. My problem is that if Johnson is the first record then it is always TRUE for the Form or if it is Smith the first record it is always FALSE for the Form. How do I fix that?
Code:
Private Sub Form_Current()
Dim varonoma, user As Variant
user = Environ("username")
varonoma = DLookup("[Surname]", "Employees", "[Username] = '" & user & "'")
If varonoma = Me.Operator Then
Me.AllowEdits = True
Else
Me.AllowEdits = False
End If
End Sub