Set subform multi-select field using Dlookup

岁酱吖の 提交于 2019-12-13 03:24:31

问题


I have a table that has multiple booths assigned to a process and a Yes/NO field for the primary booth for that process.

Process | Booth | Primary

Buff1 | 8 | No

Buff1 | 5 | Yes

etc.

I am trying to automate a form to select the primary booth on a multiselect field when the process gets selected using Dlookup.

This is the code I am using:

Me.Booth.Value = DLookup("Booth", "BoothSource", "BoothSource.Process = '" & Me.Process & "' AND BoothSource.Primary = True")

The Booth field is a multi-select field. And I get error 3032 Cannot perform this operation when I try to test. Please help. Multi-Select Example


回答1:


Multi-select fields and combo boxes are very hard to work with.

The .Value property of a multi-valued combo box is apparently a variant array, and writeable. You can set the .Value property equal to an array containing your value, instead of just your value.

Note that this bypasses many checks, such as the Limit to list property, even if value edits to the list are disallowed. You should check your inputs manually, since this might cause errors. Avoid including anything other than a string in your array (numbers, dates), since these will not trigger an error, but insert anything from Null to some item on your list to pseudorandom unicode characters.

Dim varValue As Variant
varValue = DLookup("Booth", "BoothSource", "BoothSource.Process = '" & Me.Process & "' AND BoothSource.Primary = True")
Me.Booth.Value = Array(CStr(varValue))

Note that I strongly advice against using multi select fields, so you can avoid this mess.



来源:https://stackoverflow.com/questions/49326189/set-subform-multi-select-field-using-dlookup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!