2 controls become invisible based on the option I select

  • Thread starter Thread starter Agnelo Fernandes
  • Start date Start date
A

Agnelo Fernandes

I have 3 controls in my form. [Course], [Other] present in main form and
[Speciality] in Subform.
Now, [Course] in mainform is a combo containing 4 options: Foundation Year
1, Foundation Year 2, Undergraduate, Others.
Basically, when I select ''Others'' option - the [Other] control becomes
visible orelse its invisble. I did that using the below code in after update:

If Me.Course = "Others" Then
Me.Other.Visible = True
Else: Me.Other.Visible = False
End If

That worked for me.
However, I would now like to make 2 controls i.e [Other] in main form and
[Speciality] in subform to become visble on selection of option ''Other''
orelse it should be invisible.

Any help?
 
Rather than using the slightly more readable If ... Then .... Else ... EndIF
construct, I prefer one liners:

me.other.Visible = (me.course = "Others")
me.Speciality.Visible = (me.Course = "Others")

BTW,

I would start using a naming convention for my controls if I were you; there
a several "standard" naming conventions (google on VBA +naming +conventions).

Using a naming convention makes it extremely easy to determine what type of
object (table, form, query, textbox, combo box, list, ...) you are referring
to when you write code like this.

--
HTH
Dale

Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.
 
Agnelo,
Try...
If Me.Course = "Others" Then
Me.Other.Visible = True
Me.frmYourSubformName.Form!Specialty.Visible = True
Else
Me.Other.Visible = False
Me.frmYourSubformName.Form!Specialty.Visible = True
End If

But... you also need that same code on the Current event of the form.
So, as you browse from record to record, the 2 fields show/hide
appropriately.
--
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."
 
Al,

Good catch on the Current event. I forgot all about that. Then again, I
also missed that the Specialty control was on the subform.

--
HTH
Dale

Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.



Al Campagna said:
Agnelo,
Try...
If Me.Course = "Others" Then
Me.Other.Visible = True
Me.frmYourSubformName.Form!Specialty.Visible = True
Else
Me.Other.Visible = False
Me.frmYourSubformName.Form!Specialty.Visible = True
End If

But... you also need that same code on the Current event of the form.
So, as you browse from record to record, the 2 fields show/hide
appropriately.
--
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."

Agnelo Fernandes said:
I have 3 controls in my form. [Course], [Other] present in main form and
[Speciality] in Subform.
Now, [Course] in mainform is a combo containing 4 options: Foundation Year
1, Foundation Year 2, Undergraduate, Others.
Basically, when I select ''Others'' option - the [Other] control becomes
visible orelse its invisble. I did that using the below code in after
update:

If Me.Course = "Others" Then
Me.Other.Visible = True
Else: Me.Other.Visible = False
End If

That worked for me.
However, I would now like to make 2 controls i.e [Other] in main form and
[Speciality] in subform to become visble on selection of option ''Other''
orelse it should be invisible.

Any help?
 
Thanks that helped.

Dale Fye said:
Rather than using the slightly more readable If ... Then .... Else ... EndIF
construct, I prefer one liners:

me.other.Visible = (me.course = "Others")
me.Speciality.Visible = (me.Course = "Others")

BTW,

I would start using a naming convention for my controls if I were you; there
a several "standard" naming conventions (google on VBA +naming +conventions).

Using a naming convention makes it extremely easy to determine what type of
object (table, form, query, textbox, combo box, list, ...) you are referring
to when you write code like this.

--
HTH
Dale

Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.



Agnelo Fernandes said:
I have 3 controls in my form. [Course], [Other] present in main form and
[Speciality] in Subform.
Now, [Course] in mainform is a combo containing 4 options: Foundation Year
1, Foundation Year 2, Undergraduate, Others.
Basically, when I select ''Others'' option - the [Other] control becomes
visible orelse its invisble. I did that using the below code in after update:

If Me.Course = "Others" Then
Me.Other.Visible = True
Else: Me.Other.Visible = False
End If

That worked for me.
However, I would now like to make 2 controls i.e [Other] in main form and
[Speciality] in subform to become visble on selection of option ''Other''
orelse it should be invisible.

Any help?
 
Back
Top