我有一个有特殊要求的组合框。它需要有一个只能由程序选择(基于某些检测到的标准)而不能由用户自己选择的项目。有没有办法在 VBA Access 中做到这一点?
我找到了这个解决方案,但如果没有更好的替代方案,我会这样做。我想要的是选项甚至不可见。
您应该尝试将业务逻辑移出表单。此任务需要两个函数。
Function SelectAndLock(ByRef SelectPicker As ComboBox, Id As Long)
Dim SQL_GET As String
SQL_GET = "SELECT ID, Text From ComboBoxValues WHERE [ID] = " & Id
SelectPicker.RowSourceType = "Table/Query"
SelectPicker.RowSource = SQL_GET
SelectPicker.Value = Id
SelectPicker.enabled = False
End Function
Function PopulateSelectPicker(ByRef SelectPicker As ComboBox)
Dim SQL_GET As String
SQL_GET = "SELECT ID, Text From ComboBoxValues WHERE [ID] not in (your system ids);"
SelectPicker.RowSourceType = "Table/Query"
SelectPicker.RowSource = SQL_GET
SelectPicker.Value = "" ' or null if your field is nullable
SelectPicker.enabled = True
End Function
现在,如果您的模型已经 dedected “系统”条件,您将调用
call SelectAndLock(SelectPicker,id)
这将选择系统选择的 id 并锁定组合框。
任何其他条件或默认情况下,只需调用
call PopulateSelectPicker(SelectPicker)
这将列出除用户不应该看到的系统 ID 之外的所有选项。
这只是一个概念。根据需要进行调整。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句