我有一个查找字段/组合框(颜色),表格中允许多字段(Paint)。下拉列表显示了不同颜色旁边的复选框。 它看起来像:
☑ Red
☑ Blue
☑ Green
我如何找到值' Blue'在第一次rec领域并取消选中它?我很难在表单代码中引用Colors字段:
Dim rst As Recordset
Set rst = CurrentDB.OpenRecordset("Paint", dbOpenDynaset)
With rst
.MoveFirst
MsgBox ![Color].MultiSelect
End With
我认为这会给我一个值为TRUE。但是我 该对象不支持此属性或方法 。
那么,我如何引用Color组合框然后取消选中相应的值?
答案 0 :(得分:0)
您打开的记录集似乎没有“多选”属性。有关多选字段的文档,请参阅here。
基本上,所说的是多选字段中的值本身就是记录集。您只获取了表的记录集,但没有获得该字段的记录集。你希望你的Colors表中有一个ID字段,但如果没有,可能会有不同的地方,但基本的想法应该是相同的。
你想要这样的东西:
Sub test()
Dim db As Database
Dim rs As Recordset
Dim childRS As Recordset
Dim valueToDelete As Long
valueToDelete = DLookup("ID", "tblColors", "Color = 'blue'")
'Obviously this depends on how your table is set up.
Set db = CurrentDb
Set rs = db.OpenRecordset("tblPaint")
rs.MoveFirst
Do Until rs.EOF
Set childRS = rs!Colors.Value
childRS.MoveFirst
Do Until childRS.EOF
If childRS!Value.Value = valueToDelete Then
childRS.Delete
End If
childRS.MoveNext
Loop
rs.MoveNext
Loop
End Sub