How to hide a control if another control is empty?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi everyone,

I have a bound object and a command button in a form.

Can I hide the command button and the bound object's label when the bound
object is empty, and unhide when the bound object isn't empty?

Regards,
Sam
 
Sam,

Yes, you can. You need to check the bound object and act accordingly, on
the following events:

Form Current -> so it fires when the form opens, and when moving from
record to record
Bound object Before Update -> so it fires if when the user changes it

The code (the same in both events) would look something like

vShow = Not (Me.BoundObject = "" Or IsNull(Me.BoundObject))
Me.CommandButton.Visible = vShow
Me.BoundObjectLabel.Visible = vShow

I hope my assumptions for the control names are obvious, so you can
substitute the real names.

HTH,
Nikos
 
Sorry about the mistyped descriptive line. It should be like this:

' Show BoundObjectLabel and CommandButton, only if BoundObject is not empty

So where did I do wrong? Many thanks

Regards,
Sam
 
Thank you, Nikos. Your explaination was very clear :)

But when I tried it in my application. An error message highlighting the
first line says "Type mismatch". Would you have any idea why that is?

Private Sub Form_Current()
' Show DrawingFile_Label and PDFDrawing, only if DrawingFile is not empty
vShow = Not (Me.BoundObject = "" Or IsNull(Me.BoundObject)) '<- error
Me.CommandButton.Visible = vShow
Me.BoundObjectLabel.Visible = vShow
End Sub

Regards,
Sam
 
Back
Top