Can't we enable/disable a control through expressions?

prabha_friend

Prabhakaran Karuppaih
Local time
Tomorrow, 03:53
Joined
Mar 22, 2009
Messages
1,014
=IIf([Log_Sub_Activity].[column](2)<>1,[Log_UD_ID].[Enabled]=False)

Not working through expressions :(
 
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.



- IW
 
It could be done using Conditional Formatting. It is the only way that would work on a Continuous Form.
 
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:

=IIf([Log_Sub_Activity].[column](2)<>1,[Log_UD_ID].[Enabled]=False)

Which is not working :(

But this 'code' is working properly:

Code:
If Log_Sub_Activity.Column(2) <> 1 Then Log_UD_ID.Enabled = False Else Log_UD_ID.Enabled = True
Why not the expression? Is my expression wrong? Kindly advise...
 
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:

=IIf([Log_Sub_Activity].[column](2)<>1,[Log_UD_ID].[Enabled]=False)

Which is not working :(

But this 'code' is working properly:

Code:
If Log_Sub_Activity.Column(2) <> 1 Then Log_UD_ID.Enabled = False Else Log_UD_ID.Enabled = True
Why not the expression? Is my expression wrong? Kindly advise...

Which property of the combo box are you trying to set ? Why are you not showing the full On_Change event code ?

Jiri
 
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:

=IIf([Log_Sub_Activity].[column](2)<>1,[Log_UD_ID].[Enabled]=False)

"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.
 
Thank you Doc Man. So we need a Macro Object or a Code line to do actions? No other simpler ways. Can I take it as a confirmation?
 
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

[Log_UD_ID].Enabled =IIf([Log_Sub_Activity].[column](2)<>1,FALSE,TRUE)

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.
 

Users who are viewing this thread

Back
Top Bottom