Results 1 to 4 of 4
  1. #1
    dougie is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2011
    Posts
    27

    Setting crosstab headings dynamically

    I have a crosstab based on a query. Depending on the selection criteria used in the base query the crosstab will generate different column headings, predictable in advance. For example if the user chooses 'Fruit' the crosstab column headings will be 'orange, apple, pear' and if he chooses 'Vegetable' they will be 'onion, potato, carrot'. Can I set these column headings dynamically with VBA so that I can use just one crosstab for all user selections? Creating a different crosstab for each possible user selection and hard-coding the column headings in the crosstab properties isn't a good idea as the fruits might not always be 'orange, apple, pear'.



    I'm using Access 2007.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,894
    If this can be done, I am guessing would require modifying query with QueryDef class properties.
    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
    dougie is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2011
    Posts
    27

    Solution

    Sussed it. You write VBA to append an 'IN' clause to the SQL string of the crosstab. Here's the SQL constructed by code:

    TRANSFORM Sum(qryManufNPReason.NP) AS SumOfNP
    SELECT qryManufNPReason.Department, Sum(qryManufNPReason.NP) AS [Total Of NP]
    FROM qryManufNPReason
    GROUP BY qryManufNPReason.Department
    PIVOT qryManufNPReason.NPReasonDescription In ('Supervision','New Product','Testing','Rechargeable','Laser','Tool setting','R&D');

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,894
    Ah, I was assuming a saved Access query object. I have never needed crosstabs and never done in VBA. Will have to keep this in mind. Thanks for posting solution.
    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.

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

Similar Threads

  1. Replies: 2
    Last Post: 09-21-2011, 07:23 AM
  2. Resizing column headings
    By allykid in forum Access
    Replies: 0
    Last Post: 03-10-2011, 12:58 PM
  3. Cross Tab Column Headings...
    By mhoctober in forum Queries
    Replies: 3
    Last Post: 09-10-2010, 01:21 PM
  4. Replies: 1
    Last Post: 07-30-2010, 10:28 AM
  5. Page Headings
    By maintt in forum Reports
    Replies: 2
    Last Post: 07-22-2010, 05:18 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