Option Group

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

Guest

I have an option group with 2 options in it. How would I write an "IF"
statement to say when one option is checked then make field1 visible on my
form and when the other option is checked then make field2 visible? And when
neither is checked then make neither field visible?
 
Thank you Doug but how would I write the code? I never seem to get the "IF"
statements correct.
 
Now that I think about it, an Option Group probably isn't appropriate for
this: Option Group implies that the check boxes are related, whereas your
description implies they aren't.

In the AfterUpdate of the check box, put code along the lines of:

Me.MyField.Visible = Me.MyCheckBox

This will make the control named MyField visible if the checkbox named
MyCheckBox is checked, and not visible if it isn't checked.

Depending on how your form is designed, you might also need that code in
your form's Current event.
 
I understand what you are saying. I'll use a checkbox instead. But how would
I write the code if I had 2 fields? I want to be able to "toggle" between two
fields. If the checkbox is empty then one field is visible and the other
isn't and if it's checked then the other is visible and the other isn't. Does
that make sense?
 
What type of form is it? A Continuous (or Datasheet), or a Single Form?

If a continuous or datasheet form, you may be out of luck: Access doesn't
allow you to change such properties on a row-by-row basis.
 
It's a single form.

Douglas J. Steele said:
What type of form is it? A Continuous (or Datasheet), or a Single Form?

If a continuous or datasheet form, you may be out of luck: Access doesn't
allow you to change such properties on a row-by-row basis.
 
Then put code in the form's Current event:

If Me.MyCheckBox = True Then
Me.Textbox1.Visible = True
Me.Textbox2.Visible = False
Else
Me.Textbox1.Visible = False
Me.Textbox2.Visible = True
End If

This could also be written as:

Me.Textbox1.Visible = Me.MyCheckBox
Me.Textbox2.Visible = Not Me.MyCheckBox
 
Hi Doug,
I put that code in the form's Current event but it's not working. Should I
be putting this code somewhere else too?
 
Oh and one more thing. One of my fields is an unbound calculation field.
Would that make it not work?
 
Any idea why it isn't working? Do I have to put this code on checkbox also?
 
It's working now. I forgot to add the code to the after update event of the
check box. Now I have another question though. How do I write the code if I
have 4 controls that I want to toggle? 2 need to be true and 2 false and then
vice versa.
 
If Me.MyCheckBox = True Then
Me.Textbox1.Visible = True
Me.Textbox2.Visible = True
Me.Textbox3.Visible = False
Me.Textbox4.Visible = False
Else
Me.Textbox1.Visible = False
Me.Textbox2.Visible = False
Me.Textbox3.Visible = True
Me.Textbox4.Visible = True
End If

or

Me.Textbox1.Visible = Me.MyCheckBox
Me.Textbox2.Visible = Me.MyCheckBox
Me.Textbox3.Visible = Not Me.MyCheckBox
Me.Textbox4.Visible = Not Me.MyCheckBox


I would have thought that should be pretty obvious...
 

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