问题
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