A combo box that displays info from multiple tables! (1 Viewer)

silversun

Registered User.
Local time
Today, 03:10
Joined
Dec 28, 2012
Messages
204
Hi everybody,
I have a combo box based on a query. Query itself has 8 columns based on 4 different tables. I am using the Bound Column 8 from my combo box as a value sent to another function.
I am trying to enable user to select one of the list and then based on the selection all related fields in different tables appear in a single text box, concatenated.
I have following tables:
tbl_customer: (customer_ID, first name, last name, phone, email)
tbl_makes: (make_ID, makes)
tbl_models: (model_ID, model)
tbl_molors: (color_ID, colors)
User selects a customer from combo box list once he/she sees the first Name, last Name, car make and model as well as car color. A customer can have multiple cars.
My relationship design is so that my query brings all the ID's in along with other info to display (ID's are not displayed obviously) in the combo box.
At the same time I need to have the ID of the selection passed to another function. I need that value.
I can not make the function to show all the info working.
What would be the best option to keep it simple and efficient.
I am flexible with your suggestions. I am a beginner and have not too much experience in Access or VBA. But I love working with VBA.
Thank you for your helps.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 06:10
Joined
Feb 19, 2002
Messages
43,257
Combos only work correctly if the bound column is actually unique.

The easiest way to display multiple columns from the source of the combo, is to modify the recordsource query of the form to use a left join to the lookup table. That allows you to select the columns you want to show and to bind them to individual controls on the form OR you can concatenate them and bind the mushed field to a control. Using this method, the values will always show as long as some item has been selected from the combo and no code is required. If you do end up binding the individual columns be VEEEEERRRRRRY careful to set the locked property to yes for these controls to prevent the user from accidentallly updating them. You don't want someone changing "mustang" to "accord" and having that become the permanent name for that particular auto model.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:10
Joined
May 7, 2009
Messages
19,230
your tables are not Related to each other.
your combo for 4 tables combine will not bring the result you want.
you need separate combos for each table.
you need a resulting table that will have all 4 ids you selected from the 4 combos.
 

silversun

Registered User.
Local time
Today, 03:10
Joined
Dec 28, 2012
Messages
204
Here is a picture of my relationships attached.
This is from the query with 4 related tables. The owner_ID is the value I need to pass around other functions.
The owner_ID can deliver all necessary info about any car once the user selects it.
Am I doing it right?
 

Attachments

  • relationships.JPG
    relationships.JPG
    34.5 KB · Views: 204

silversun

Registered User.
Local time
Today, 03:10
Joined
Dec 28, 2012
Messages
204
Hi Pat,
As I said before, I am not expert in VBA or Access. I need you to explain your suggestion where you said: "... modify the recordsource query of the form to use a left join to the lookup table."
I have a simple select query that takes all the fields from different tables. Did you mean I need to create a look up table or temp table or something like that?
It looks like what you said is exactly what I am looking for except it is not easy for me to perform it.
Appreciate your helps
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:10
Joined
May 7, 2009
Messages
19,230
if column 8 on your combo refers to customer_ID, then you make a Query for your form's recordsource:
Code:
select * from tbl_carsOwners 
WHERE
customer_ID = FORMS!yourForm!yourComboName;
drag the fields from this query as textbox input of your form.
change the make_id, color_id, model_id as comboboxes.
the combo rowsource is the id and the description from their respective table.
bound to column 1, with column count property=2, column width=0";1".

on the AfterUpdate event of the original combo, do a Requery on the form so it will pull the pertinent record(s) associated with that customer_id.
 

silversun

Registered User.
Local time
Today, 03:10
Joined
Dec 28, 2012
Messages
204
@ Arnelgp,
My column 8 in my combo box refers to owner_ID in tbl_carsOwners. It takes all the ID's from from that table. I am going to work on what you said this afternoon. I have to go to work now. Thank you for help. I will keep you posted.
 

silversun

Registered User.
Local time
Today, 03:10
Joined
Dec 28, 2012
Messages
204
Thank you all for helps. I found an easy way to show all the fields in a text box when I was reading other threads in this website and I realized that solves my issue.
Here is what I am using, just for information:
Code:
Me.txt_car_owner = [cmb_selectCustomer].[Column](0) & " " & [cmb_selectCustomer].[Column](1) & ........
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 06:10
Joined
Feb 19, 2002
Messages
43,257
It doesn't really solve the issue unless you use the same code in the form's Current event.
 

Users who are viewing this thread

Top Bottom