Hide and change backcolor of txtBox

  • Thread starter Thread starter SoggyCashew
  • Start date Start date
S

SoggyCashew

Hello, I have 5 text boxes on my form with a value of 0. I wanted the
txtBoxes visible = false and if there is something other than 0 in the box
then change that text box to visible = true and the txtBox background to red
with a white forecolor. How would I do this? Thanks!
 
Damon, This wont work because this is on a form that has LOTS of text boxes
due to it being a calendar. I just need it to work with 5 perticular text
boxes not all of them on the form. Is there a way to change your code to
acomplish this? I thought about using conditional formating and it would work
but how would I get the visible part to work in conditional formating if its
possible? Thanks!
--
Thanks,
Chad


Damon Heron said:
Depends on where the data is coming from. If it is part of records that you
are paging thru, then in the current event of the form,
put:
Private Sub Form_Current()
Dim MyObject As Control

For Each MyObject In Me ' Iterate through each element.
With MyObject
If .ControlType = acTextBox Then
If .Value = 0 Then '
.Visible = False
Else
.Visible = True
End If
End If
End With
Next

End Sub

In design view, set the backcolor and forecolor to red and white, since they
won't be visible, so there is no need to do it in code.

Damon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top