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

I'm trying to populate a combo box using different tables based on...

Status
Not open for further replies.

Sarlacc

Technical User
Mar 24, 2003
5
CA
I'm trying to populate a combo box using different tables based on a selection in a different combo box. Any help?
 
Sarlacc,

One way is to use the AfterUpdate event of the first combo box. That event could use the value of ComboBox1 and a Select Case statement to set the Row Source Type and Row Source property for the second combo box. Then Requery the second combo box.

Example:

Code:
Sub Combo1_AfterUpdate()
Dim Combo1_value As String
Dim Combo2_Row_Source_Type As String
Dim Combo2_Row_Source As String
Combo1_value = Me.Combo1

    Select Case Combo1_value
        Case "X"
            Combo2_Row_Source_Type = "Table/Query"
            Combo2_Row_Source = "SELECT DISTINCTROW [tblMembers].[LastName] FROM [tblMembers];"
        Case "Y"
            Combo2_Row_Source_Type = "Table/Query"
            Combo2_Row_Source = "SELECT * [tblVisitors].[Name] FROM [tblVisitors];"
        Case "Z"
            Combo2_Row_Source_Type = "Table/Query"
            Combo2_Row_Source = "SELECT * [tblGuests].[FullName] FROM [tblGuests];"
    End Select
Me.Combo2.RowSourceType = Combo2_Row_Source_Type
Me.Combo2.RowSource = Combo2_Row_Source
Me.Combo2.Requery
End Sub
 
Hey Thanks for the help, it worked great. :D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top