Hello,
I have a dropdown box with the values from 1-5 and I want to show textboxes
accourding to the value given in the dropdown! e.g. The value selected is 3
and I have Unit1; Unit2; Unit3 textboxes displayed and Unit4 and Unit5
hidden. How do I do that? Without VBA if possible. :/
Thank you.
David W - 10 Mar 2005 15:31 GMT
This is for what I gather you are wanting to do
It looks like your wanting to show an "x" amount of textboxes for the value
selected.
Set the textboxes visible property to "No"
Try this in the combos after update event
If any orther code exist, you might want to delete the "exit sub" from each
if statement.
Private Sub myCombo_AfterUpdate()
If me.mycombo=1 then
me.unit1.visible=true
me.unit2.visible=false
me.unit3.visible=false
me.unit4.visible=false
me.unit5.visible=false
exit sub
End if
If me.mycombo=2 then
me.unit1.visible=true
me.unit2.visible=true
me.unit3.visible=false
me.unit4.visible=false
me.unit5.visible=false
exit sub
End if
If me.mycombo=3 then
me.unit1.visible=true
me.unit2.visible=true
me.unit3.visible=true
me.unit4.visible=false
me.unit5.visible=false
exit sub
End if
If me.mycombo=4 then
me.unit1.visible=true
me.unit2.visible=true
me.unit3.visible=true
me.unit4.visible=true
me.unit5.visible=false
exit sub
End if
If me.mycombo=5 then
me.unit1.visible=true
me.unit2.visible=true
me.unit3.visible=true
me.unit4.visible=true
me.unit5.visible=true
exit sub
End if
End Sub
This will only work on the current record
> Hello,
>
[quoted text clipped - 6 lines]
>
> Thank you.
Wayne Morgan - 10 Mar 2005 15:36 GMT
You may be able to do this without VBA if you use Conditional Formatting.
The problem is that the textbox would still "be there" if the user tabbed
into it or clicked in the correct location of the form. To do this using
Conditional Formatting, set the back color and fore color of the textbox to
match the color of the form. However, as you can see, this could create
confusion and problems for the user.
Using VBA, you would use the AfterUpdate event of the combo box and the
Current event of the form. The AfterUpdate event will catch when a user
changes the value in the combobox and the Current event will get the value
in the combobox as you move from record to record.
Example code:
Select Case Me.cboMyCombobox
Case 1
'Hide boxes as needed here
Case 2
'Hide boxes as needed here
Case 3
Me.txtUnit1.Visible = True
Me.txtUnit2.Visible = True
Me.txtUnit3.Visible = True
Me.txtUnit4.Visible = False
Me.txtUnit5.Visible = False
Case 4
'Hide boxes as needed here
Case 5
'Hide boxes as needed here
Case Else
MsgBox "Bad Value"
End Select

Signature
Wayne Morgan
MS Access MVP
> Hello,
>
[quoted text clipped - 6 lines]
>
> Thank you.
Marshall Barton - 10 Mar 2005 17:45 GMT
>I have a dropdown box with the values from 1-5 and I want to show textboxes
>accourding to the value given in the dropdown! e.g. The value selected is 3
>and I have Unit1; Unit2; Unit3 textboxes displayed and Unit4 and Unit5
>hidden. How do I do that? Without VBA if possible. :/
You really have to use VBA to set the text box's Visible
property. Since you have nice uniform names for them, the
code in the combo box's AfterUpdate event procedure can be
very simple:
Dim K As Interger
For k = 1 To 5
Me("Unit" & k).Visible = (k <= Me.combobox)
Next k

Signature
Marsh
MVP [MS Access]
John Vinson - 11 Mar 2005 06:42 GMT
>Hello,
>
[quoted text clipped - 4 lines]
>
>Thank you.
You're getting several good answers to the question - but I'd like to
"unask" the question. I suspect that the need to do this implies that
you have an incorrect table structure!
If textboxes Unit1 to Unit5 are bound to table fields Unit1 to Unit5,
then you have embedded a one-to-many relationship (one to five to be
exact) *in each record*. This is *bad design*! If you have a one to
many relationship, consider modeling it as a one to many relationship,
with two tables; use a Subform with five (or two, or eleven) rows for
the units rather than textboxes.
John W. Vinson[MVP]
xb00t - 11 Mar 2005 17:25 GMT
Thank you for the answers.
John, I'm doing this as a college coursework. It doesnt have to work
properly. I just have to attend to it. ;)
> >Hello,
> >
[quoted text clipped - 17 lines]
>
> John W. Vinson[MVP]