Results 1 to 4 of 4
  1. #1
    AndyC121 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2015
    Posts
    37

    union query from multiple crosstabs

    I have been try to create a union query from multiple crosstabs. I get either no data or just the first headings duplicated, searched for lots of answers but not quite sure what im doing any pointer please. Below are my crosstab queries:

    TRANSFORM Count([COSHH table].ID) AS CountOfID
    SELECT [COSHH table].ID, [COSHH table].[Name of substance]
    FROM [COSHH table] INNER JOIN [Fire fighting] ON [COSHH table].[Fire fighting measures].Value = [Fire fighting].ID
    WHERE ((([COSHH table].ID)=True))


    GROUP BY [COSHH table].ID, [COSHH table].[Name of substance]
    PIVOT [Fire fighting].[Fire fighting measures];

    TRANSFORM Count([COSHH table].ID) AS CountOfID
    SELECT [COSHH table].ID, [COSHH table].[Name of substance]
    FROM [COSHH table] RIGHT JOIN Hazards ON [COSHH table].Hazards.Value = Hazards.ID
    WHERE ((([COSHH table].ID)=True))
    GROUP BY [COSHH table].ID, [COSHH table].[Name of substance]
    PIVOT Hazards.Hazards;


    TRANSFORM Count([COSHH table].ID) AS CountOfID
    SELECT [COSHH table].ID, [COSHH table].[Name of substance]
    FROM [COSHH table] INNER JOIN Locations ON [COSHH table].[Location used].Value = Locations.ID
    WHERE ((([COSHH table].ID)=True))
    GROUP BY [COSHH table].ID, [COSHH table].[Name of substance]
    PIVOT Locations.Locations;


    TRANSFORM Count([COSHH table].ID) AS CountOfID
    SELECT [COSHH table].ID, [COSHH table].[Name of substance]
    FROM [COSHH table] INNER JOIN PPE ON [COSHH table].[PPE required].Value = PPE.ID
    WHERE ((([COSHH table].ID)=True))
    GROUP BY [COSHH table].ID, [COSHH table].[Name of substance]
    PIVOT PPE.[PPE Required];


    TRANSFORM Count([COSHH table].ID) AS CountOfID
    SELECT [COSHH table].ID, [COSHH table].[Name of substance]
    FROM [COSHH table] INNER JOIN [Route of exposure] ON [COSHH table].[Route of exposure].Value = [Route of exposure].ID
    WHERE ((([COSHH table].ID)=True))
    GROUP BY [COSHH table].ID, [COSHH table].[Name of substance]
    PIVOT [Route of exposure].[Route of exposure];

  2. #2
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,929
    for a union query to work, all queries must have the same number of columns and datatypes. Crosstabs can have varying number of columns (even if you know there are the same number, access doesn't). You can get round this by setting the column headings in the crosstab properties.

    If you actually want a very wide query then you don't use a union query, instead you need tow more.

    The first is one that will generate a list of all the rows you want to appear (regardless of whether they are in each of the crosstabs)

    Not clear from what you have posted but perhaps [COSHH table].ID and [COSHH table].[Name of substance]

    then create a new query, bring the one above in and left join to all of your crosstabs

    Also not clear about your criteria

    WHERE ((([COSHH table].ID)=True))

    this will bring through all records where ID<>0 and is not null. ID's are usually autonumbers and never zero or null so the criteria is pointless. But perhaps it means something else...

  3. #3
    AndyC121 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2015
    Posts
    37
    Hi Ajax,
    thanks for the reply. maybe im going about this all the wrong way.
    Im trying to generate a report from the form "COSHH Form" in my attached example database. the report has to look like "report1" (this is just an example of the report and wont be an embedded word doc) with the boxes ticked or crosses in them corresponding to the selections made from the cosh form.
    Attached Files Attached Files

  4. #4
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,929
    the report looks like it is one report per substance, So I think all you need is the one crosstab - but put the column headers in query so you can see all of them - see the query properties, you would populate it with the text value e.g. "Very Toxic", "Toxic", "Corrosive" etc

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

Similar Threads

  1. Union Query or Multiple Queries.???
    By MFS in forum Queries
    Replies: 9
    Last Post: 08-30-2014, 04:48 AM
  2. Reports from Crosstabs
    By balajigade in forum Reports
    Replies: 2
    Last Post: 03-19-2014, 02:10 PM
  3. Replies: 8
    Last Post: 10-22-2012, 07:43 PM
  4. Modules using Crosstabs
    By OTSeraph in forum Access
    Replies: 1
    Last Post: 02-10-2012, 10:50 AM
  5. Union Query and multiple entries
    By krutoigoga in forum Queries
    Replies: 1
    Last Post: 07-08-2011, 07:17 AM

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