It's all about context. Yes you can enable/disable controls through expressions, but it depends on where you are putting those expressions.
The syntax you've used makes me think you are trying to achieve it in a place in which you cannot do so. Are you placing that code in the Enable or Control Source property of the control? If so, that's not going to work.
You need to do this in VBA. And that syntax is a little different and its all based on Events (an action occuring). So please explain the the conditions in which you want your control gets enabled/disabled. What action triggers it changing it's status?
It's all about context. Yes you can enable/disable controls through expressions, but it depends on where you are putting those expressions.
The syntax you've used makes me think you are trying to achieve it in a place in which you cannot do so. Are you placing that code in the Enable or Control Source property of the control? If so, that's not going to work.
You need to do this in VBA. And that syntax is a little different and its all based on Events (an action occuring). So please explain the the conditions in which you want your control gets enabled/disabled. What action triggers it changing it's status?
Not to mention it would be much easier and cleaner to do in VBA, something like:
Code:
If Me.Column2 <> 1 Then Me.Log_UD_ID.Enabled = False
Of course you would replace the value of whatever control you're actually working with, and the values you don't want them to be, etc.. I just used your example data.
I am enabling/disabling the Log_UD_Id (Textbox) on the Change Event of Log_Sub_Activity (Multicolumn ComboBox) by using the following expression in the Expression Builder:
I am enabling/disabling the Log_UD_Id (Textbox) on the Change Event of Log_Sub_Activity (Multicolumn ComboBox) by using the following expression in the Expression Builder:
The direct answer to the question: why does the code work and the expression not work?
is that the expression always and only returns a value whereas the code has the option to do something else - like take an action. The way I would read that expression is:
"If the selected column of that combo-box or list-box control is not 1 then return the value of the sub-expression [Log_UD_ID].[Enabled]=False - which will be either true or false depending on whether the control in question actually IS enabled or not."
Another problem is that using IIF returns a value, but if you have the syntax that starts with the "=IIf" sequence, you already have lost the ability to do anything with the result because there is nothing to the left of the "=" sign.
I would say that a macro or code statement is the best of all possible ways to do actions, yes. Expressions can ONLY return values (implied: return them TO something.)
Now, let's muddy the waters just a smidgeon. If you executed code that did something like
you would be using code that includes a formula that returns T/F to set a control property, and that might actually work. But it would have to be executed as a code segment, not an expression.