Auto populate a combo box (1 Viewer)

BJS

Registered User.
Local time
Today, 20:03
Joined
Aug 29, 2002
Messages
109
I accidentally posted this in "general"...so I am posting it here under "forms", since it is "form" related. My intention was not to double-post...sorry.
Summerwind had posted an example to auto populate a combo box. The code below follows his example, but is not working for me:

The fields I have on my form are:

cboCompany
cboLocation

cboCompany is based on tblCompany( with fields CompanyName, Location)

When I update the cboCompany field, I want the cboLocation combo box to populate with all locations for the company that was entered into the cboCompany combo box on the form. E.g. The company "Visions" may be exist in the tblCompany with 3 different locations: Visions (Las Vegas), Visions (Ohio), Visions(California). When I pick the company "Visions" from the cboCompany combo box, I want the cboLocation combobox to be populated with "Las Vegas", "Ohio", and "California".

The code is as follows but returns empty records in cboLocation:


Code:
Dim StrSource As String

StrSource = "SELECT Location FROM tblCompany WHERE tblCompany.CompanyName Like " & Me.cboCompany.Column(1)
With Me.cboLocation
.RowSource = StrSource
.SetFocus
.Dropdown
End With

Can anyone help with this...thank you.
 

Oldsoftboss

AWF VIP
Local time
Tomorrow, 05:03
Joined
Oct 28, 2001
Messages
2,499
Seems you have your table structure wrong. You should have all you companies in one table and the location and companyID as a foreign key in another table

Attached is a cut down cascading combobox example.
Notice the only code required is a requery.

HTH

Dave
 

Attachments

  • db2.zip
    14.2 KB · Views: 162
Last edited:

Users who are viewing this thread

Top Bottom