Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581

    I don't want anyone to change information on a form

    I have a combo box on a form. Once the information is entered and the user leaves the form, I don't want anyone to be able to go back and make changes. I already have a way to delete the information. However, if someone goes in and changes the combo box, there are too many problems. Is there a way to make it so that the user cannot reopen the form and make changes without doing what I want them to do?

  2. #2
    Join Date
    Apr 2017
    Posts
    1,673
    On fly (I haven't Access available at moment to check the syntax):
    To table the form is based on, add a field IsLocked (boolean);
    On form you'll have a control booIsLocked. Set the default value for control FALSE, and hide the control (Visible = FALSE);
    In AfterUpdate event of combo box add a code row (depending on datatype of combo's source field)
    Code:
    Me.booIsLocked = (Nz(Me.cbbYourCombo,0)=0 )
    or
    Code:
    Me.booIsLocked = (Nz(Me.cbbYourCombo,"")="" )
    ;
    As next row of AfterUpdate event of combo box and into OnCurrent event of form add code
    Depending on you wanting to lock the whole entry, or only the combobox:
    Code:
    Me.AllowEdits = NOT(Me.booIsLocked)
    or
    Code:
    Me.cbbYourCombo.Enabled = NOT(Me.booIsLocked)
    Edit. You can name the table field IsEnabled instead, with according control booIsEnabled, and in formula calculating booIsEnabled, replace "=" with "<>". Then you can drop NOT() function in code setting AllowEdits or Enabled properties.

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,016
    Use this code to prevent editing of Records:

    Code:
    Private Sub Form_Current()
      Me.AllowEdits = False
    End Sub

    And then, using an appropriate event, use:

    Code:
    Me.AllowEdits = True

    to allow editing of the current Record.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    or you could just set the form dataentry property to true - then users can only create new records

  5. #5
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    Ajax, Thanks. That was the easiest, but unfortunately is won't work. Using dataentry doesn't let the other information be seen because it only allows the user to create new records.

    Avril, You lost me with those codes. I didn't understand, "As next row of AfterUpdate event of combo box and into OnCurrent event of form add code
    Depending on you wanting to lock the whole entry, or only the combobox:"

    Linq, won't that not allow any edits if I put it on current? I need the user to make an entry at first. After the entry, I don't want him to go back into the form and make changes without going through the process that I've set up. Also, I'm not sure what the appropriate event would be on the allowedits=true.

  6. #6
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    Linq, I take that back.
    I hate that I doubted your wisdom. I put the code to not allow edits into the after update and it works perfectly. Thanks.

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Private Sub Form_Current()
    Me.AllowEdits = Me.NewRecord
    End Sub

    Or just set the form as AllowEdits No as this will allow viewing existing records but not edit and also allow new record.

    And if you don't want them to be able to change the combobox selection on the new record (they really get only one shot?), use AfterUpdate code to lock the combobox. Are there other fields that require data entry after the combobox selection?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    I know. It sounds strange to only give them one chance to get the choice right. If they change the combo box after they open it again, it messes up all the calculations. So, I gave a process to change it that will not mess anything up. It easier too. So all I needed was to only allow the user to enter it once. I put the code Linq gave in the after update of the combo box. Now, they can pick and choose which one they need. Even if they mess up, as long as they don't close the form, change can be done. I tested it and it works. Looks like yours will work too. I'll make note of it. If this messes up, gonna do that one. So far, so good. Thanks for all the help.

  9. #9
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    there are plenty of situations where you don't want to allow records to be changed once entered. Invoices, bank transactions and the like where once entered, if it is incorrect, you are required to enter a correcting entry rather than alter the original

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    No, I mean change their choice on the new record before record is committed, before they leave the new record, before they even leave the combobox. What if they accidentally clicked on wrong list item, not allowed to correct? Of course no change when they go back to the existing record.

    Just setting the form AllowEdits property should be enough, no VBA code.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  11. #11
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    I'm not sure what happened. Went back to the form and it wasn't working the way I wanted it to.
    I tried:
    Private Sub Form_Current()
    Me.AllowEdits = Me.NewRecord
    End Sub

    It worked, but locked the all the fields. Is there a way to lock only the combo box?

  12. #12
    Minty is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,001
    I think this may be a design problem, If you have a host of calculations based on the combo box update, then simply recalculate on update of that value.

    Unless you have stored the results of all those calculations, which in an ideal world you shouldn't do. You should just recalculate them for display.

    The other option would be to set the value of the combobox on a landing form for new records, this would then be passed to edit form with the combo value permanently locked.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  13. #13
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,016
    Code:
    Private Sub Form_Current()
     
     If Me.NewRecord Then
      Me.ComboName.Locked = False
     Else
      Me.ComboName.Locked = True
     End If
    
    End Sub

    or, for the shortcut enthusiasts

    Code:
    Private Sub Form_Current()
     Me.ComboName.Locked = Not Me.NewRecord
    End Sub

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  14. #14
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Did you read post 10?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  15. #15
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,016
    Did you read Post # 11?

    Quote Originally Posted by UT227 View Post

    ...It worked, but locked the all the fields. Is there a way to lock only the combo box...
    The OP only wants the Combobox to be non-editable...not all of the Controls!

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 9
    Last Post: 11-07-2017, 03:40 AM
  2. Replies: 2
    Last Post: 02-05-2015, 03:51 PM
  3. Replies: 2
    Last Post: 10-03-2014, 10:07 AM
  4. Replies: 3
    Last Post: 05-02-2014, 09:27 AM
  5. Change information in a query
    By calobo in forum Queries
    Replies: 3
    Last Post: 03-01-2012, 10:32 AM

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