I want a text box to appear only when a combo box is set

K

Kevin C Niven

I have a combo box and a text box on my form. If the combo box is not
set to some value (which I assume means it's null), I'd like the text
box to be invisible. As soon as the user sets the combo box, I'd like
the text box to appear.

I believe, perhaps wrongly, that I need to add some code to my form's
Current event. I also believe, perhaps wrongly, that the code needs
to take the following approximate form:

Private Sub Form_Current()

If Me.MyCbo.Value = "" Then
Me.MyTxt.Visible = False
Else
Me.MyTxt.Visible = True
End If

End Sub

But this does not work. Maybe the problem is in the test. I have
tried "If Me.MyCbo.Value = Null Then" and "If Me.MyCbo.Value Is Null
Then" which lead to runtime errors. I have also reversed the False
and True and tried just "If Me.MyCbo.Value Then".

Can someone help by telling me what code I need to add and where?

Many thanks,
Kevin
 
K

Kevin C Niven

PS: Both the cbo box and the txt box have row source/control source
and control source values, so if you tell me to put an Iif in one of
these, please tell me how I can write it so that the current sources
still work.
 
A

Al Campagna

Kevin,
On the form's OnCurrent event...
MyTxt.Visible = Not IsNull(MyCbo)
You'll also need the same code on the AfterUpdate event of MyCbo
MyTxt.Visible = Not IsNull(MyCbo)
--
hth
Al Campagna
Microsoft Access MVP
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."
 
K

Kevin C Niven

Kevin,
   On the form's OnCurrent event...
        MyTxt.Visible = Not IsNull(MyCbo)
   You'll also need the same code on the AfterUpdate event of MyCbo
        MyTxt.Visible = Not IsNull(MyCbo)

Thank you very much for that reply. That answered the question I
asked very well.

However, the question I asked was not actually the question I should
have asked. :)

My form is continuous. That means if one of the MyCbos is set, then
all of the MyTxts show. Is there a way to make it such that MyTxt
shows only in those instances on the continuous form where MyCbo is
set?

Apologies for getting my own question wrong!

Thanks again,
Kevin
 

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

Top