Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how can i make links between combo's

Status
Not open for further replies.

miketamp

Technical User
Jan 28, 2005
20
GR
hi i have a form called "dieta" which have 5 combo boxes "ctl1" "Ctl2" "Ctl3" "Ctl4" "Ctl5" all of them are not visible exept the ctl1. I want when then "ctl1" takes the value "small" the ctl2 be visible else when the Ctl1 takes the value "big" then Ctl3 be visible and all the others not visible.Now when ctl3 is visible and takes the value "one" then the ctl4 be visible and all the others not visible, else when the ctl3 takes the value"two" then the Ctl5 be visible and all the others be not. i have this code:
Private Sub Ctl1_AfterUpdate()
If Ctl1.Text = "small" Then
Ctl2.Visible = True
Ctl3.Visible = False
ElseIf Ctl1.Text = "big" Then
Ctl2.Visible = false
Ctl3.Visible = true
End If
End Sub

Private Sub Ctl3_AfterUpdate()
If choose.Value = "one" Then
Ctl4.Visible = True
Ctl5.Visible = False
ElseIf choose.Value = "two" Then
Ctl4.Visible = False
Ctl5.Visible = True
End If
End Sub
the code works fine for the ctl1 but when i 'm trying to select values from the Ctl3 it does nothing
why?
Can you please help me?thanx...
 
Mike

I think a SELECT CASE would work well here with the AfterUpdate event procedure.

Code:
[COLOR=blue]
Private Sub [b]Ctl1[/b]_AfterUpdate()[/color]

Dim strSelection as String

strSelection = Nz(Me.[b]Ctl1[/b], "")

Select Case strSelection 

   Case "small"
        Me.Ctl2.Visible = True
        Me.Ctl3.Visible = False
        Me.Ctl4.Visible = False
        Me.Ctl5.Visible = False

   Case "big"
        Me.Ctl2.Visible = False
        Me.Ctl3.Visible = True
        Me.Ctl4.Visible = False
        Me.Ctl5.Visible = False

   Else Case
        'Set values here if neither big nor small chosen
        'or add another Case selection
        'Else Case should always be the last in the list

End Select

End Sub

[COLOR=blue]
Private Sub [b]Ctl3[/b]_AfterUpdate()[/color]

Dim strSelection as String

strSelection = Nz(Me.[b]Ctl3[/b], "")

Select Case strSelection 

   Case "one"
        Me.Ctl4.Visible = True
        Me.Ctl5.Visible = False

   Case "two"
        Me.Ctl4.Visible = False
        Me.Ctl5.Visible = True

   Else Case
        'Set values here if neither big nor small chosen
        'or add another Case selection
        'Else Case should always be the last in the list

End Select

Note that since you can not control the way users enter data, you have to accommodate the behaviour backwards and forwards. For example, they may be at Ctl5, and decide to go back and change the value in Ctl1.

Richard
 
Hi there
thanks for the answer. i try the way that you sugest but i have exactly the same problem the code works for the ctl1 but not for the ctl3. ican not understand why.can you please help me?
 
Do you understand the logic of the above code?

What specifically does not work for Ctl3?

We have to determine if the code is wrong or if the problem is that code is not "firing" because of a control naming problem.

Richard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top