Results 1 to 5 of 5
  1. #1
    lios1984 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jan 2012
    Posts
    29

    Allowedits according to the record

    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

  2. #2
    rivereridanus is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    71
    Correct me if I'm wrong, but it looks to me like this code will fire for every record change like you want it to, but Dlookup will always give you the same value each time since it's based on Environ("username"). Whoever is in the database is that user, so each time they fire that code, they are always either Operator, or they are not- but it's not going to change from record to record.

  3. #3
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    There is another possibility here. Are you sure the Usernames listed in your table are correct? DLookup will return the FIRST match it finds, so if the username is johnson25, the Dlookup is going to give you "Johnson" every time.

    Another possibility is that there is no match for "User" in the employee table, so that varonoma is Null (that's OK for Variants data type), and the IF is always false in some cases.

    But what data in the current record are you using for comparison? Is it me.Operator?

    John

  4. #4
    lios1984 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jan 2012
    Posts
    29
    Yes, the User will remain the same since it is the same PC. The reason is that I don't want anyone to modify a record who is not authorised to. So since the User is the same, there will be a check if the User is authorized to modify the record by checking if he/she is the Operator. The field Operator is changing according to the record. So both of you, rivereridanus and John_G, are right. My problem is this: Dlookup does return the same value every time but Me.Operator does not change according to the record. It is like the code is executed only for the first record of the form and does not repeat itself when I move to the next record.

  5. #5
    lios1984 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jan 2012
    Posts
    29
    Haven't solved it yet. Any ideas?

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

Similar Threads

  1. Replies: 8
    Last Post: 07-06-2013, 05:13 PM
  2. Replies: 14
    Last Post: 05-25-2012, 02:40 AM
  3. Replies: 2
    Last Post: 11-27-2011, 07:08 PM
  4. AllowEdits in Subform
    By Jackie in forum Forms
    Replies: 3
    Last Post: 03-02-2011, 10:51 AM
  5. Form combo box not working with AllowEdits = False
    By jgelpi16 in forum Programming
    Replies: 3
    Last Post: 02-04-2011, 05:08 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