Help on Querying with Cascading ComboBoxes (1 Viewer)

DBApprentice

On Error GoTo AWF *****:
Local time
Today, 16:10
Joined
Dec 24, 2018
Messages
150
Hi,

I am trying to build a query that collects some information and export it to Excel. But since many values from the DB is coming from cascading Combobox.

During the tests I noticed when I run the query it is duplicating the entries, i.e. I have just 4 records, but when I simply include the tables on the Query Designer and run it is repeating the records to show each of the cascading combo values.

Any ideas to help me to build this query? :banghead:

PS: DB is attached and the query is qryExportFullCardsXls, the cascading are PillarFK and PillarElements among others.
 

Attachments

  • DB Test.zip
    848.4 KB · Views: 96

pbaldy

Wino Moderator
Staff member
Local time
Today, 12:10
Joined
Aug 30, 2003
Messages
36,123
That query appears to run correctly, returns 5 records. If it doesn't include the combo's table, make sure you include a join. Without a join you get a Cartesian product, all combinations of the records in the tables.
 

DBApprentice

On Error GoTo AWF *****:
Local time
Today, 16:10
Joined
Dec 24, 2018
Messages
150
That query appears to run correctly, returns 5 records...

It is not working as expected, pbaldy. Despite of returning 5 records, the last column that was intended to return the "Methodology" instead of "3".

If you check the new attachment you will see that the 2 last columns will only return the IDs from their original tables. Also you will notice that it is returning only one record that repeat itself... a strange Cartesian product.


...If it doesn't include the combo's table, make sure you include a join. Without a join you get a Cartesian product, all combinations of the records in the tables.

Can you show me where I should put the JOIN?

Thanks!
 

Attachments

  • DB Test.zip
    848.6 KB · Views: 106

pbaldy

Wino Moderator
Staff member
Local time
Today, 12:10
Joined
Aug 30, 2003
Messages
36,123
Add the pillar table to the query and then return the description from that table:

SELECT tblCardObservations.CardNumber, tblCardStatuses.CardStatus, tblCardObservations.ObservationStartDate, tblAreas.AreaName, tblCategories.Category, tblCardObservations.ObservationDescriptionENG, tblCardObservations.ImmediateActionENG, tblCardObservations.CommentsClassConsidENG, tblCardObservations.FeedbackMsgENG, tblCardObservations.FeedbackByTeamSupervisorFK, tblCardObservations.FeedbackDate, tblPillars.PillarName
FROM tblPillars RIGHT JOIN (tblCategories INNER JOIN (tblCardStatuses INNER JOIN (tblCardRatings INNER JOIN (tblAreas INNER JOIN tblCardObservations ON tblAreas.AreaID = tblCardObservations.AreaFK) ON tblCardRatings.CardRatingID = tblCardObservations.RatingFK) ON tblCardStatuses.CardStatusID = tblCardObservations.CardStatusFK) ON tblCategories.CategoryID = tblCardObservations.CategoryFK) ON tblPillars.PillarID = tblCardObservations.PillarFK
ORDER BY tblCardObservations.ObservationStartDate DESC;
 

DBApprentice

On Error GoTo AWF *****:
Local time
Today, 16:10
Joined
Dec 24, 2018
Messages
150
Add the pillar table to the query and then return the description from that table...

OK, it is working now and returns the "WORKPLACE" as I need. Thanks!!!!:D

But how do I put the value from the PillarElement? This value depends on the SafetyPillar.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 12:10
Joined
Aug 30, 2003
Messages
36,123
I've logged out of my computer to start fixing dinner. I can take a look later tonight or someone will chime in.
 

DBApprentice

On Error GoTo AWF *****:
Local time
Today, 16:10
Joined
Dec 24, 2018
Messages
150
I've logged out of my computer to start fixing dinner. I can take a look later tonight or someone will chime in.

No rush and everybody is more than welcome to jump in!
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 12:10
Joined
Aug 30, 2003
Messages
36,123
Sorry, got distracted last night. ;)

The selection of the value depended on the first combo, but the value once selected doesn't, does it? How's this?

SELECT tblCardObservations.CardNumber, tblCardStatuses.CardStatus, tblCardObservations.ObservationStartDate, tblAreas.AreaName, tblCategories.Category, tblCardObservations.ObservationDescriptionENG, tblCardObservations.ImmediateActionENG, tblCardObservations.CommentsClassConsidENG, tblCardObservations.FeedbackMsgENG, tblCardObservations.FeedbackByTeamSupervisorFK, tblCardObservations.FeedbackDate, tblPillars.PillarName, tblPillarElements.Element
FROM tblPillarElements RIGHT JOIN (tblPillars RIGHT JOIN (tblCategories INNER JOIN (tblCardStatuses INNER JOIN (tblCardRatings INNER JOIN (tblAreas INNER JOIN tblCardObservations ON tblAreas.AreaID = tblCardObservations.AreaFK) ON tblCardRatings.CardRatingID = tblCardObservations.RatingFK) ON tblCardStatuses.CardStatusID = tblCardObservations.CardStatusFK) ON tblCategories.CategoryID = tblCardObservations.CategoryFK) ON tblPillars.PillarID = tblCardObservations.PillarFK) ON tblPillarElements.PillarElementID = tblCardObservations.PillarElementFK
ORDER BY tblCardObservations.ObservationStartDate DESC;
 

DBApprentice

On Error GoTo AWF *****:
Local time
Today, 16:10
Joined
Dec 24, 2018
Messages
150
Sorry, got distracted last night. ;)
The selection of the value depended on the first combo, but the value once selected doesn't, does it? How's this? ...

Regarding your question, that´s right: the dependency is only when I have those cascading combos on the form, once the user chooses one and the other the bound table will save the information independently.

You code works like a charm, Paul!

So when it comes to this type of join I should go for RIGHT JOIN, am I right? Unless I missed something from you SQL code.

Thanks a lot for the help!:)
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 12:10
Joined
Aug 30, 2003
Messages
36,123
Happy to help!

Not necessarily a RIGHT JOIN. I had to do that because there wasn't always data in those fields in the observations table. Double or right click on the join line between one of those pillar tables and the observations table to edit it. The three options describe what the different joins will do. Those 3 options will change the join to either RIGHT, LEFT or INNER as appropriate to the choice. Play with them and see how the results change.
 

Users who are viewing this thread

Top Bottom