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

Populating A Combo Box Dynamically

Status
Not open for further replies.

jackman

Programmer
Jul 25, 2000
1
0
0
US
I am working in a subform in datasheet view with the following fields:&nbsp;&nbsp;vendor, vendor contacts.&nbsp;&nbsp;When the operator selects a vendor, the appropriate contacts related to the vendor should be populated in the vendor contacts combo box.&nbsp;&nbsp;I know that I can change the Row Source property to reflect all of the vendor contacts available for that particular vendor; however, all vendor contacts fields that do not relate to that particular vendor disappear.&nbsp;&nbsp;This also happens when the form is set to continuous.<br><br>After some contemplation, I realize that I could manually populate the combo box and include all of the non-relating vendor contacts but this would allow the operator to select a vendor contact that does not relate to the vendor selected in the previous field.<br><br>I would greatly appreciate any advise.<br><br>
 
On the AfterUpdate Event of the Vendor Field, put the following, changing the bolded areas appropriately:<br><br>Private Sub Vendor_AfterUpdate()<br>&nbsp;&nbsp;&nbsp;Dim strSQL as String<br>&nbsp;&nbsp;&nbsp;strSQL = &quot;SELECT <b>Contact</b> FROM <b>YourTable</b> WHERE(((<b>Vendor</b>) = '&quot; & Me.<b>Vendor</b> & &quot;'));&quot;<br>&nbsp;&nbsp;&nbsp;Me.<b>cboContact</b>.RowSource = strSQL<br>&nbsp;&nbsp;&nbsp;Me.<b>cboContact</b>.Requery<br>End Sub <p>Jim Lunde<br><a href=mailto:compugeeks@hotmail.com>compugeeks@hotmail.com</a><br><a href= Application Development
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top