Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2021
    Posts
    9

    Question Group repeating records in a query - Database about chemical products

    Hi everyone! I am creating a database to manage information about chemical products and I hope you can help me with this problem.



    Click image for larger version. 

Name:	Figure1.png 
Views:	21 
Size:	21.7 KB 
ID:	44059


    As you can see in the first table (tblChemicalProducts), all the products have a primary hazard, but not all of them have a secondary hazard, so I created another table to store the information about secondary hazards (see Figure 2) and made a relationship with the main table through the SubstanceID field (see Figure 3). This is because a product may have a single secondary hazard, several secondary hazards, or no secondary hazard.


    Click image for larger version. 

Name:	Figure2.png 
Views:	21 
Size:	17.5 KB 
ID:	44060
    Click image for larger version. 

Name:	Figure3.png 
Views:	21 
Size:	8.6 KB 
ID:	44061


    For example, as you can see in the second table (tblSecondaryHazards), Sulfuric Acid (SubstanceID=1001) doesn’t have a record associated with it because it doesn’t have a secondary hazard. Methanol (SubstanceID=1002) has one record associated with it because it has only one secondary hazard. Finally, Chlorine (SubstanceID=1003) has two records associated with it because it has two secondary hazards (it's an oxidizing substance and also corrosive).

    My problem is that I don’t know how to create a query that returns a table like the one shown in Figure 4:

    Click image for larger version. 

Name:	Figure4.png 
Views:	23 
Size:	27.6 KB 
ID:	44062


    As you can see, I need to group all the secondary hazards of a product in one single record of the query, but right now I am obtaining a different result (like the one shown in Figure 5). I don’t want that the products with two or more secondary hazards appear repeated in the query. Does someone know if that is possible? Do I have to use SQL code to do that? Thanks in advance.

    Click image for larger version. 

Name:	Figure5.png 
Views:	23 
Size:	25.9 KB 
ID:	44063

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Could use VBA code to build a comma separated string of SecondaryHazard data and display in a single field. Review http://allenbrowne.com/func-concat.html

    Forcing each secondary hazard into its own field would utilize a complicated CROSSTAB query. How many secondary hazards could be possible?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Join Date
    Apr 2017
    Posts
    1,792
    Change database structure to something like:
    tblChemicalProducts: SubstanceID, Formula, Description;
    tblHazards: HazardID, Hazard, [HazardType];
    tblChemicalHazards: ChemicalHazardID, SubctanceID, HazardID, [HazardType]

    Depending on hazards having always same type (i.e. primary or secondary), or having the type depending on chemical, you'll have field for HazardType either in hazards table or in chemical hazards table.

  4. #4
    Join Date
    Jan 2021
    Posts
    9
    Thank you very much! I used the VBA code from the link that you gave me and was able to do exactly what I wanted to achieve.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. quote report group and count like products
    By samos1023 in forum Reports
    Replies: 1
    Last Post: 05-23-2018, 12:05 PM
  2. Chemical Database Layout.
    By dlab85 in forum Database Design
    Replies: 15
    Last Post: 03-08-2013, 08:37 AM
  3. Replies: 8
    Last Post: 04-24-2012, 01:05 PM
  4. Group Headers Not Repeating in a Report
    By kristyspdx in forum Reports
    Replies: 4
    Last Post: 12-20-2011, 05:00 PM
  5. Repeating Records
    By windwardmi in forum Reports
    Replies: 13
    Last Post: 05-22-2010, 02:54 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums