Hi,
I would like to make a bound text box not visible if it is empty (not just
disable it). This option is not available from the standard conditional
formatting feature (at least, not that I can find).
I thought of calling a class module function via Expression Builder for the
control. I have written a basic function, but don't seem to be able to
pass the relevant arguments correctly. It seems to me that I need to pass
two arguments: the name of the control, and the value of the database
field. The function is intended to set the control's .Visible property to
FALSE (if it is empty) and to return the value to display (blank or some
other value). And I would like to make the function generic so that I can
use it in future for any control on any form.
This is what I have so far for the function:
'---------------
Public Function HideIfEmpty(Ctl Name As Variant, ctlValue As Variant) _
As Variant
Dim ctl As Control
Set ctl = CtlName
HideIfEmpty = ctlValue
ctl.Visible = Iif(Nz(ctlValue ,"") = "", False, True)
End Function
'--------------
I think that my main problem is in passing the CtlName value. This would
need to be a fully qualified pathname if the function is to be generic, but
selecting the control using Expression Builder, only the local controlname
is inserted. Thus the Expression Builder result looks like:
=HideIfEmpty([txtControlname],[FieldValue])
When running the form, the function gives an error 2427 "You entered an
expression that has no value."
Obvioulsy I am not doing this correctly. Any pointers would be much
appreciated!
Cheers,
Lyn.
I would like to make a bound text box not visible if it is empty (not just
disable it). This option is not available from the standard conditional
formatting feature (at least, not that I can find).
I thought of calling a class module function via Expression Builder for the
control. I have written a basic function, but don't seem to be able to
pass the relevant arguments correctly. It seems to me that I need to pass
two arguments: the name of the control, and the value of the database
field. The function is intended to set the control's .Visible property to
FALSE (if it is empty) and to return the value to display (blank or some
other value). And I would like to make the function generic so that I can
use it in future for any control on any form.
This is what I have so far for the function:
'---------------
Public Function HideIfEmpty(Ctl Name As Variant, ctlValue As Variant) _
As Variant
Dim ctl As Control
Set ctl = CtlName
HideIfEmpty = ctlValue
ctl.Visible = Iif(Nz(ctlValue ,"") = "", False, True)
End Function
'--------------
I think that my main problem is in passing the CtlName value. This would
need to be a fully qualified pathname if the function is to be generic, but
selecting the control using Expression Builder, only the local controlname
is inserted. Thus the Expression Builder result looks like:
=HideIfEmpty([txtControlname],[FieldValue])
When running the form, the function gives an error 2427 "You entered an
expression that has no value."
Obvioulsy I am not doing this correctly. Any pointers would be much
appreciated!
Cheers,
Lyn.
Comment