Results 1 to 4 of 4
  1. #1
    mortonsafari is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2015
    Location
    Brisbane, Queensland, Australia
    Posts
    39

    Prevent data entry or deletion

    I have a field/control on a form which is an Identifier (Member Number in a General Number format) and which gets the focus once the form is loaded.
    I don’t want to ‘lock’ the field/control because the control gets the focus on Form load.


    However, I do not want users who input data to be able to alter or delete the number once it has been input into the form (I can go back to the table to do that if necessary).
    What is the most effective way to stop users from altering or deleting the number without locking the field/control?
    Would a Message Box saying “You cannot alter this number – see the Administrator” and then an OK button which moves to the next field/control be the best option?
    Any assistance and ideas appreciated.
    Many thanks
    mortonsafari

  2. #2
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,372
    The most effective way is to do exactly what the 'locked' or 'disabled' property is designed for. If you're not going to allow users to change the value, why set the focus to it? Instead, set the focus to a form button (typically the form close button is the first object in a form in the tab order) or some other control. Otherwise, you are going to have to write code for the OnChange event that resets the value to something that was there before, but there is no need for all that bother. Or you can accomplish the same with a GotFocus event - still unnecessary.
    Last edited by Micron; 01-31-2016 at 09:30 PM. Reason: add ref. to other control
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,845
    if a field is locked, it can still have the focus, just users cannot change it. Only disabled controls cannot get the focus (or controls such as lines)

  4. #4
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    As for your message to users, you can use something like this, replacing MemberNumber and NextControl with the actual names of your Controls:

    Code:
    Private Sub MemberNumber_KeyDown(KeyCode As Integer, Shift As Integer)
     
     If KeyCode <> vbKeyTab And KeyCode <> vbKeyReturn Then
     
      If Me.MemberNumber.Locked = True Then
       MsgBox "You cannot alter this number – see the Administrator!"
       NextControl.SetFocus
      End If
     
     End If
    
    End Sub

    If the Control is Locked and they hit any key other than Tab or Enter, the message will pop up and Focus will go to whatever Control you specify.

    Linq ;0)>

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

Similar Threads

  1. Replies: 4
    Last Post: 12-21-2015, 10:57 PM
  2. Replies: 2
    Last Post: 06-11-2015, 08:42 AM
  3. Replies: 7
    Last Post: 03-05-2015, 07:34 AM
  4. Replies: 2
    Last Post: 02-29-2012, 12:51 AM
  5. Prevent Duplicate Entry
    By kilosierra71 in forum Forms
    Replies: 4
    Last Post: 07-28-2011, 03: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