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!

Relating fields in a form

Status
Not open for further replies.

cwebb

Technical User
Feb 7, 2000
5
US
I am trying to use a combo box in a form with a pull-down menu (i.e. Business Name). I need the remaining fields (i.e. Business Address, City, State, Zip, etc.) to update when the business in the pull-down menu changes. How can this be done? I have been through 3 books and can not find a solution.
 
Add this to the combo boes &quot;After Update&quot; Event procedure.<br>
<br>
Private Sub Combo8_AfterUpdate()<br>
Dim db As Database<br>
Dim rst As Recordset<br>
Set db = CurrentDb<br>
SQL = &quot;Select * From Business Where BusID = &quot; & Combo8.Column(0)<br>
Set rst = db.OpenRecordset(SQL)<br>
Me!BusName = rst.Fields(&quot;BusName&quot;)<br>
Me!BudAddr = rst.Fields(&quot;BudAddr&quot;)<br>
Me!BusCity = rst.Fields(&quot;BusCity&quot;)<br>
<br>
End Sub<br>
<br>
<br>
Now in your combo box put both the Business's unique ID and their name<br>
Put the ID in the first column and give it a 0&quot; width so it will not show.<br>
When you click on the Business name it will pass the ID to the SQL code and find the exact match.<br>
<br>
<br>
OK<br>
<br>
<br>
<br>

 
If it's for display only, here's another method I once used, saved a lot of space on the form: <br>
<br>
Build a query for combo's RowSource that contains a concatenated string with all the data. In column 1 of the query put your key, in column 2 put something like [BusinessName] & &quot; &quot; & [Address] & &quot; &quot; & [City] etc. Set your Bound column to 1, your Column Count to 2, and Column Widths to 0;x (x=width in inches needed to display all that stuff), set the width of the combo box to the same number.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top