Results 1 to 8 of 8
  1. #1
    Gert01 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2016
    Posts
    4

    How to sort field names by the result of a query and create a report that contains grouped results ?

    Hello,

    I'm trying to make a local application and I'm stuck.
    I'm inputting data into a form ( linked to the table 'questions' ) and based on the data input, I let a query run a calculation ( query1 ).

    This query1 creates new field names and the result of the calculations are numbers.

    Here's my question :
    A) How can I sort the field names based on the result of the query ? -> The query only calculates 1 record at the time ( with 30 columns ), as the application requests input and gives a related output ( output is 50 columns ).
    B) I want to make a report from the sorted field names. However, based on the calculation of query1, I want to sort them into 4 groups ( group1, group2, group3, group4 ) which are defined by the value of the result ( like group1 >8, group2 >6, group3 >4, group4<=4 )
    I guess it's easier if the field names are converted to column names with the value as the second column, but I don't manage to understand how to do...

    Any help would be highly appreciated !

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Provide example raw data and desired output.

    Can't 'sort' fields, sort records. Arrange bound controls on form or report into whatever order you desire.
    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
    Gert01 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2016
    Posts
    4
    Hi,

    the result of my query would look like below :

    Click image for larger version. 

Name:	Query result.PNG 
Views:	5 
Size:	2.1 KB 
ID:	23462


    Then based on the score that's calculated in the query, I would like to create a report which ranks the fields in the columns of 'highly recommended', 'recommended',...


    Desired report output :
    Click image for larger version. 

Name:	Report output.PNG 
Views:	5 
Size:	3.6 KB 
ID:	23461


    But here I'm stuck, as sorting only works ( as far as I know ) on the individual fields, which in my case only contain 1 value.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    What is the rule for assigning the descriptive headings? Like: 0-15 is Not Recommended, 16-20 is ...

    You show query output. What does the raw data look like? If the query represents raw data, it is not normalized structure.
    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.

  5. #5
    Gert01 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2016
    Posts
    4
    I'm using a form with questions to fill a table. The form looks like below :

    Click image for larger version. 

Name:	Questions table.PNG 
Views:	5 
Size:	4.8 KB 
ID:	23465

    The table then shapes up like this :
    Click image for larger version. 

Name:	Questions table design.PNG 
Views:	5 
Size:	2.5 KB 
ID:	23466


    Then based on the table, I made a query which looks like this : ( filled in in the 'Field' cel )

    Click image for larger version. 

Name:	Query design.PNG 
Views:	5 
Size:	5.7 KB 
ID:	23467

    This gives me then a score for each carmaker.

    With another query, I convert the score to the recommendation level, you assumed correctly a basic nested Iif function :

    BMW score : Iif ([Query1]![BMW]>30;"Highly recommended"; Iif ([Query1]![BMW]>20;"Recommended"; Iif ([Query1]![BMW]>10;"Slightly interesting"; Iif ([Query1]![BMW]<=10;"Not recommended"))))


    However I'm not sure if I need to run this query before making the report that's sorting the car brand according to the recommendation level, as I was also trying to get the report structured in a way that all "highly recommended" carmakers would go in a dedicated column based on their score ( over 30 ) and similar for the other levels.

    I just hope that my structure is ok ( as I'm a rather novice user of Access... )
    Attached Thumbnails Attached Thumbnails Rec query.PNG  

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    The table is not a normalized data structure.

    I suspect generating that columns by category output will not be easy.

    If you want to provide db for analysis, follow instructions at bottom of my post.
    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.

  7. #7
    Gert01 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2016
    Posts
    4
    Probably a transpose function would work out fine, but I'm not sure how to construct it. ( type of query or using VBA of which I have no knowledge )

    Thanks for the quick replies, guess I should dig a bit deeper.

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    That would be a CROSSTAB query but I don't think your data is properly structured for that. Might need an intermediate UNION query then run the CROSSTAB. Gets complicated. Proper data structure makes a big difference.

    And yes, VBA writing records to a 'temp' table is an option.
    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. dynamic field names (sort of)
    By mountainclimber in forum Access
    Replies: 12
    Last Post: 08-13-2015, 08:05 AM
  2. Replies: 1
    Last Post: 04-01-2015, 09:45 AM
  3. Replies: 3
    Last Post: 01-04-2015, 03:00 PM
  4. Replies: 2
    Last Post: 08-01-2013, 01:33 PM
  5. Retun grouped results of a query
    By cbenisch in forum Access
    Replies: 3
    Last Post: 05-28-2013, 06:27 PM

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