By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,651 Members | 1,694 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,651 IT Pros & Developers. It's quick & easy.

How to lock field/records associated with a combo box selection

P: 1
Hello, I am having a difficult time locking a field/records that are only associated with the currently selected item in a combo box. A subform generates specific titles based on a combo box selection (for example, the titles are all sci-fi). In the next instance, I give users the ability to enter in values in a field in the subform, and a submit button would then lock all of the records so no further changes can be made by them. However, I can implement a lock feature that locks titles, but it ends up locking all of the records, and not just the records associated with the combo box.
- How do I reference specific fields/records based on a combo box in VBA
- Additionally, how do I compare records within the same combo box selection to ensure no two items in the same field have the same value?


Example code I'm trying to use:
Private Sub Submit_Click()
Dim Msg, Style, Title, Response, Mystring
Msg = "Do you want to submit?"
Style = vbYesNo
Title = "Submission"
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then
Mystring = "Yes"

'This is where I would try to use the lock property of a field and lock based on what the combo box selection is
If Me.fsubtitles!Priority.Locked = False Then
Me.fsubtitles!Priority.Locked = True
Else
Me.fsubtitles!Priority.Locked = False
End If
Else
Mystring = "No"
End If
End Sub
Feb 6 '17 #1

✓ answered by Seth Schrock

Only one question is allowed per thread, so I'll answer the one related to the title of the question and you can ask your second question in a new thread.

If you change the property of a control on a form or report, that property is changed for all records being displayed, as you have discovered and this can't be changed. However, hope is not lost. What you can do is to create another field to mark those records which should be locked and those which can be edited. Then in your control's Before_Update event, you can check if the record is locked and cancel the change if it is while providing a message stating the reason for the cancellation.

Share this Question
Share on Google+
1 Reply


Seth Schrock
Expert 2.5K+
P: 2,931
Only one question is allowed per thread, so I'll answer the one related to the title of the question and you can ask your second question in a new thread.

If you change the property of a control on a form or report, that property is changed for all records being displayed, as you have discovered and this can't be changed. However, hope is not lost. What you can do is to create another field to mark those records which should be locked and those which can be edited. Then in your control's Before_Update event, you can check if the record is locked and cancel the change if it is while providing a message stating the reason for the cancellation.
Feb 9 '17 #2

Post your reply

Sign in to post your reply or Sign up for a free account.