vba 表单加载时如何锁定子表单中的特定行?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4849141/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to lock specific rows in a subform when a form loads?
提问by owlie
I have a subform containing records with a Yes/No field displayed as a checkbox on the subform. When the main form is loaded, I need to lock all checked fields so that the user cannot undo what a previous user did: they should only be able to check/uncheck the boxes that were unchecked at the start of thier session.
我有一个包含记录的子表单,其中是/否字段显示为子表单上的复选框。加载主表单时,我需要锁定所有选中的字段,以便用户无法撤消先前用户所做的操作:他们应该只能选中/取消选中在会话开始时未选中的框。
Is it possible to iterate through all the records in a subform and lock the records selectively based on the field value when a form is loaded?
是否可以遍历子表单中的所有记录并在加载表单时根据字段值有选择地锁定记录?
I know I can put something like
我知道我可以放一些类似的东西
If (Me.chkItemReceived.Value = -1) Then
Me.chkItemReceived.Locked = True
Else
Me.chkItemReceived.Locked = False
End If
in the subform OnCurrent event but this prevents the user from unchecking a box they may have checked accidently. I can iterate through the records on the subform but can't figure out how to lock the records at row-level.
在子表单 OnCurrent 事件中,但这可以防止用户取消选中他们可能意外选中的框。我可以遍历子表单上的记录,但无法弄清楚如何在行级锁定记录。
My other solution is to split the form into two subforms of course - items checked vs. items not but would rather keep it to the one form.
我的另一个解决方案当然是将表单拆分为两个子表单 - 检查的项目与未检查的项目,而是宁愿将其保留在一个表单中。
Thanks for your help!
谢谢你的帮助!
回答by BIBD
No, there is no way to have specific rows (or records) locked in the GUI in MS Access. If you change the properties of a control on one record, it changes it on all records in the subform.
不,无法在 MS Access 的 GUI 中锁定特定行(或记录)。如果您在一个记录上更改控件的属性,它会在子窗体中的所有记录上更改它。
I don't think you could even get away with doing row-level locking directly on the underlying table. Typically, locking is done to prevent others from editing your records. But in this case, you are trying to prevent yourself from editing them.
我认为您甚至无法直接在基础表上执行行级锁定。通常,锁定是为了防止其他人编辑您的记录。但在这种情况下,您试图阻止自己编辑它们。
The two methods you describe (OnCurrent and separate SubForms) are probably your best options. For cleanliness of the code, I'd choose the latter.
您描述的两种方法(OnCurrent 和单独的 SubForms)可能是您最好的选择。为了代码的整洁,我会选择后者。
回答by Comrad_Durandal
Well, you basically gave yourself the solution to your problem - if I am reading your question right. You can set it so when you iterate to the next record, certain controls are locked from editing based on the value of those or other controls. You are not actually locking the rows in the tables, of course, but you are preventing the user from changing the value of the locked controls.
好吧,您基本上给了自己解决问题的方法-如果我正确阅读了您的问题。您可以设置它,以便当您迭代到下一条记录时,某些控件会根据这些或其他控件的值被锁定而无法进行编辑。当然,您实际上并未锁定表中的行,但您正在阻止用户更改锁定控件的值。
If you mean to prevent other users from editing the record you just edited - then this would not solve your issue.
如果您的意思是阻止其他用户编辑您刚刚编辑的记录 - 那么这不会解决您的问题。