If Statement

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

Guest

How would I write an "IF" statement for the following:

I have a combo box on my main form with a value list that I choose from.
When a user selects "English" from the combo box I want "English1" on my
subform to be visible and "Metric1" not to be visible. If the user selects
"Metric" then I want "Metric1" on my subform to be visible and "English1" not
to be visible.

How would I write this and where do I put this code?

Any help would be greatly appreciated!
 
In the AfterUpdate event procedure of the combo box ...

I would not use an 'If' statement at all ...

Me.English1.Visible = (Me.NameOfCombo = 'English')
Me.Metric1.Visible = (Me.NameOfCombo = 'Metric')

Using an If statement it would look like ...

If Me.NameOfCombo = 'English' Then
Me.English1.Visible = True
Me.Metric1.Visible = False
Else
Me.English1.Visible = False
Me.Metric1.Visible = True
End If

Same result, just a little more verbose.
 
Thanks for the response. I do have one question though. Does it matter that
these fields are on a subform? Do I need to specify that in the code you
wrote?
 
Yep, that would be something like ...

Me.NameOfSubformControl.Form.English1.Visible = etc.
 
Perfect! Thanks for your help!

Brendan Reynolds said:
Yep, that would be something like ...

Me.NameOfSubformControl.Form.English1.Visible = etc.
 
Hello again,
Actually I can't seem to get it to work using the code you gave me below.

I tried to type "Me.Nameofsubformcontrol.Form.English1.Visible"
After I typed the "Me." I typed the subform name and then "form" but then it
didn't list the control names. Is that the correct way to type it out or am I
missing something? I hope I explained this right.
 
The Intellisense feature does not list the control names under those
circumstances. That's just a limitation of the Intellisense feature. Just go
ahead and type the name of the control anyway.

A common mistake is to type the name of the form that is being used as a
subform, rather than the subform control that contains the form. But as long
as you have that right, it should work.
 

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