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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to link two combo boxes?

Status
Not open for further replies.

hshaker

Technical User
Jun 29, 2007
66
CA
Hi there,

I would like to implement three combo boxes that are linked together.

You have a list of items for first combo box and the second combo box's list is based on the first combo box and the third combo box's list will be based on the second combo box.

The only problem that I have is that when a user selects all the items in all the three combo boxes and then later on wants to change his second selection in the second combo box, the third combo box will not be updated. And therefore, I hide the second and third combo boxes initially, then when the user selects the second combo box , the third combo box will appear.

Is there any constructive way of doing this? Could you please provide some sample code?
 
A common way is to dynamically build the RowSource property of the dependant combo in the AfterUpdate (or Change) event procedure of the parent combo.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi there,

Here is my code for two cascading combo box for now.

Private Sub cboReason1_AfterUpdate()
Dim strSQL As String
'Dim strSQLSF As String

cboReason2 = Null
cboReason3 = Null

strSQL = "SELECT tblDowntimeReason2.Downtime2ID FROM tblDowntimeReason2 "
strSQL = strSQL & " WHERE tblDowntimeReason1.DowntimeID1 = '" & cboReason1 & "'"
strSQL = strSQL & " ORDER BY tblDowntimeReason2.DowntimeReason2;"

cboReason2.RowSource = strSQL

'strSQLSF = "SELECT * FROM tblDemo "
'strSQLSF = strSQLSF & " WHERE tblDemo.RowField = '" & cboRowField & "'"

'Me!sfrmForm.LinkChildFields = "RowField"
'Me!sfrmForm.LinkMasterFields = "RowField"
'Me.RecordSource = strSQLSF
Me.Requery
End Sub


Rememeber I have several tables. In first table, for ie, I have the list of all downtime reason 1. In the second table I have two columns that links Downtimereason 1 and Downtimereason2.

Should I create a one big table with all the downtime reasons linked together? If so, how do I merge several tables into one table?


With the code that I just pasted, when I select an item in the first combo box, it says please enter a parameter value .. .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top