Show me the Option! ... or Don't

G

Guest

Let's say I have a form with two controls: ITEM_TYPE (a combo box), and
OPTION_1 (a check box). I want OPTION_1 to be invisible, except when
ITEM_TYPE is equal to "X", in which case OPTION_1 becomes visible so the user
can choose to check the option box if they wish.

WHAT I TRIED... I set the OPTION_1 Visible property to No and then inserted
code i got off this forum into ITEM_TYPE's AfterUpdate event.
The code is: Me.OPTION_1.Visible = (Me.ITEM_TYPE = "X") and it works just
fine.

THE PROBLEM... Yes the code works, but I put it in the wrong event. It only
begins working when the ITEM_TYPE field has just been updated. When i first
open the form, the OPTION_1 control remains invisible even on records where
ITEM_TYPE = "X" until ITEM_TYPE receives and looses focus, then all is well
as I scroll through the records.

MY QUESTIONS...
1. Is there a single event i can insert this code into to make it work right?
2. If not, then is it bad practice to put the code in multiple events to
make it work?
3. Am I going about this all wrong?
 
M

Mark via AccessMonster.com

Copy the same bit of code to the Form_Current event. This way, the checkbox will update every time you move to another record, or if the data in the combobox changes.

Sometimes, you have to put things in multiple events to take care of different circumstances. Instead of copying the same code everywhere, you could just put "Call Item_Type_AfterUpdate()" in the Form_Current event. Then, when you want to make some changes to what happens when the combobox data changes, you only have to change it in one place.
 
G

Guest

I used the code in the right places but I got an error when i went to a new
record and the ITEM_TYPE field was blank.

"Error Code 94: Invalid use of Null"

if you're still reading this thread Mark, any suggestions on how to handle a
null here?

Here is my complete function:

Private Sub
Me.OPTION_1.Visible = (Me.ITEM_TYPE = "X")
End Sub

Thanks
HM
 
D

Douglas J. Steele

Me.OPTION_1.Visible = (Nz(Me.ITEM_TYPE, "") = "X")

or

Me.OPTION_1.Visible = ((Me.ITEM_TYPE & "") = "X")
 

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