combobox dependent on another combobox (1 Viewer)

Les W

New member
Local time
Today, 02:03
Joined
Aug 31, 2015
Messages
7
I am having trouble with my drop down list in a second combobox. I have 3 tables as follows:

Table 1: s, fields: Source _ID(pk), Source _Name
Table 2: w, fields: Location_ID(pk), Location_Name
Table 3 (junction table): sw, fields: SW_ Source _ID(pk), SW_Location_ID(pk)

I have 2 comboboxes on my form: cbo1 and cbo2. Cbo2 is dependent on the value in cbo1.

Cbo1 has the following RowSource stmt:

SELECT .[Source_ID], .[Source_Name] FROM s;

Cbo2 has a query as the RowSource. The query stmt is:

SELECT sw.SW_Source_ID, w.Location_Name
FROM s INNER JOIN (w INNER JOIN sw ON w.Location_ID = sw.SW_Location_ID) ON s.Source_ID = sw.SW_Source_ID
WHERE (((s.Source_ID)=[forms]![Form1]![cbo1]));

Cbo2 will correctly display the drop down list associated with the choice in cbo1. The problem is that no matter which item in the cbo2 item list I choose, cbo2 will only show the first item in the list. For example, if the drop down list is A, B, C, D and I choose item C, item A shows as my choice. What I want is to show S_Name in cbo1 and it’s corresponding list of names as W_Name in cbo2 (which it does) and the ability to choose item B or C or D.

I do have a Requery AfterUpdate of cbo1, which works fine i.e. the list in cbo2 does change when the cbo1 selection changes.
 

Les W

New member
Local time
Today, 02:03
Joined
Aug 31, 2015
Messages
7
Thanks, jdraw. Excellent videos. I have no problem when there is a simple relationship between 2 tables. The problem has only come up when there is a many-to-many relationship with a junction table.
 

jdraw

Super Moderator
Staff member
Local time
Today, 05:03
Joined
Jan 23, 2006
Messages
15,393
Can you zip a copy of your database and post?
 

Les W

New member
Local time
Today, 02:03
Joined
Aug 31, 2015
Messages
7
Hope I did this upload correctly. The zip file is attached.

Please note that I am very new to Access, so, there is a lot of testing in the file and it is quite 'messy'. There are extra queries and forms and vba coding. The form that has the 2 comboboxes is frmInventoryReceivedInput.
 

Attachments

  • TCTR 2015 - 9 21 15.zip
    370.9 KB · Views: 108

jdraw

Super Moderator
Staff member
Local time
Today, 05:03
Joined
Jan 23, 2006
Messages
15,393
Les,
I added an event to the second combo cboWLocation; and changed the column for display purposes.
Code:
Private Sub cboWLocation_AfterUpdate()
MsgBox "You selected " & Me.cboSupplySource.Column(1) & "  value in Placed where is " & Me.cboWLocation
End Sub
 

Les W

New member
Local time
Today, 02:03
Joined
Aug 31, 2015
Messages
7
When I add that routine the message shows the name in the cboWLocation.

I was looking for the number in the ID field (in the same table) corresponding to that location. For example, if the cboWLocation was 'cages' I would want to have the number 1, if it was 'garbage' then the number 35 should be returned.

Does that make sense?
 

jdraw

Super Moderator
Staff member
Local time
Today, 05:03
Joined
Jan 23, 2006
Messages
15,393
Yes it makes sense, but I think your issues start with the use of the Lookup at the table field level in SupplySource WarehouseLocation. I do not use lookups at table field level.
I don't think your current set up has the LocationID as part of the rowsource. Seems to me you have SupplySourceId or LocationName, but I do NOT u se lookups at table field so could be way off base.
 

Les W

New member
Local time
Today, 02:03
Joined
Aug 31, 2015
Messages
7
Hmmm. :banghead: I think, when I designed the query, Access put those Row Sources in the Lookups for the fields in the junction table - I'm pretty sure I didn't do that (at least not on purpose!). What is an alternative method to lookups at table field level?

Thanks for your help so far.
 

jdraw

Super Moderator
Staff member
Local time
Today, 05:03
Joined
Jan 23, 2006
Messages
15,393
Can you give readers an overview of the application in plain English in 5-6 lines? Basically the "business your in"-- this should match up with your relationships screen; then some specifics about the form and the combos --details on what they represent and what you want to do on that form.

I notice that some of your tables in the relationships window are not joined to others?? And some tables are not in the relationships window?
What exactly is Inventory? Bales? WLWL?

You should adopt a naming convention that does not have embedded spaces.
 
Last edited:

Les W

New member
Local time
Today, 02:03
Joined
Aug 31, 2015
Messages
7
Regarding my file and tables, a lot of what you see is just testing and trials while I learn different things about Access. They are not permanent nor is everything being used.

We are in the clothing recycling business. We send out trucks daily to collect clothes, we also purchase clothes and other people just drop them off. The collected clothes, depending on the source, can go to a few different places in the warehouse. The first part of the application is tracking the quantity received, where the clothes come from, and where they end up. The next phase of the application will be the processing of the clothes into usable and non-usable and the hard part will be tracking all that activity by employee. That is why, in the first part, it is important to know where the clothes end up, which is the basis of the dependent combo boxes on the InventoryInput form.
 

Les W

New member
Local time
Today, 02:03
Joined
Aug 31, 2015
Messages
7
Thanks, I will work through it today (and hopefully get cbo2 to do what I tell it to do!). I only recently began on this creating applications journey. I have some programming experience but I am totally new to Access. Setting up the proper tables and creating the proper relationships has been a bit of a challenge so far. And understanding some of the syntax has been frustrating as my query to this group has shown. But with determination and help from people like yourself, it will be a fun journey.
 

Users who are viewing this thread

Top Bottom