Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    NewbyForAccess is offline Advanced Beginner
    Windows 7 64bit Access 2003
    Join Date
    Sep 2015
    Posts
    49

    Sorting in a Report

    I'm trying to figure out the best way to sort descending on a report, but here's my problem. I have the fields I need included and they sum for each group. I created a textbox to calculate the percentage between the two fields; however, I need to sort on the data that's in the textbox and not from the two given fields. Is there a way to program Access to sort by this calculated textbox and not from any of the fields in my report? Hope someone can guide me where I need to be to get this figured out.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    One solution is to move the calculation to the report's source query, then sort on that field. You can also sort on an expression in grouping and sorting.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    NewbyForAccess is offline Advanced Beginner
    Windows 7 64bit Access 2003
    Join Date
    Sep 2015
    Posts
    49
    I tried everything I could think of to get this to sort including trying to use an expression, but because the item that I want to sort by is not a field, it's not allowing me to sort. The calculations are working perfectly, thank goodness. I think because this is a textbox with a calculation only, Access isn't recognizing it enough to use for sorting. If anyone can give me an idea on what code to use, I'd sure appreciate it. Obviously, what I've tried isn't working. I spent several hours on it yesterday and still can't get it to sort on this textbox. Thanks for the tip. Just wish it would have worked for me so I could move on. LOL

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Did you try moving the calculation out to the query? Can you post the db here?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    NewbyForAccess is offline Advanced Beginner
    Windows 7 64bit Access 2003
    Join Date
    Sep 2015
    Posts
    49
    Yes, I tried using the query but had no luck. What I have are four fields in my query. One is for customer, one for part number, and then two fields containing the piece count for the part numbers, one being for good pieces and one for scrap pieces. I wanted to calculate the percentage of scrap by using the following formula: =Scrap/Scrap + Good. Because I used "sum" for the two fields (scrap pcs and good pcs), I used the formula =[SumOfSCRAP PCS]/([SumOfGOOD PCS]+[SumOfSCRAP PCS]) in the control source for the textbox. The textbox is formatted for percent. When viewing the report, it's working perfectly for all calculations; however, I can't get it to sort in descending order.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Can you attach the db here?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    NewbyForAccess is offline Advanced Beginner
    Windows 7 64bit Access 2003
    Join Date
    Sep 2015
    Posts
    49
    I don't think I can attach the db here because it's from my job. It all works except the sorting on a textbox field containing the formula for calculation. In my query, I only have the data and no calculation field. I am trying to avoid editing my tables and thought I'd be able to sort it through the report. Maybe I'm just not sure what code to use for the expression. Remember, I'm definitely a newby at programming the db. Haven't had a class in this for over 30 years and that was on dBase III. I'm showing my age now. LOL I'm trying to learn the code and have been working by trial and error for the most part. Thanks for whatever help I can get!

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    The same formula you have in the textbox should work in Sorting and Grouping, without the "=", like

    [SumOfSCRAP PCS]/([SumOfGOOD PCS]+[SumOfSCRAP PCS])
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    NewbyForAccess is offline Advanced Beginner
    Windows 7 64bit Access 2003
    Join Date
    Sep 2015
    Posts
    49
    Paul, did I tell you that you're my hero! I can't believe this worked. I was thinking I had to give it a SortBy command or something similar so that's what I was trying to do. I just checked it out and was so totally shocked that I only needed to sort by my formula. I can't thank you enough for helping me with this. I've spent the past few days and several hours trying to figure it out. I am so totally happy right now! I know I've got lots to learn on the program and am so appreciative for the members of this forum who are so willing to help newbies like me. You are absolutely awesome! Thank you again and again!

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    NewbyForAccess is offline Advanced Beginner
    Windows 7 64bit Access 2003
    Join Date
    Sep 2015
    Posts
    49
    Hey, Paul. It's the pest again. This is working perfectly, but I have a question I know you can answer if you don't mind. The command button for my report to print is based off of dates that are inserted on my main form, but the report pulls all the information for all my data and doesn't pull just from the dates specified. Is the reason it doesn't pull only by the criteria dates because I don't have a date field added to my report? This is the code I'm using for my command button:

    Private Sub Command33_Click()
    On Error GoTo Err_Command9_Click
    Dim stDocName As String
    Dim stLinkCriteria As String
    If IsNull(Me.txtStartDate) Or _
    IsNull(Me.txtEndDate) Then
    MsgBox "Please enter date criteria."
    Exit Sub
    End If

    DoCmd.OpenReport "Top Ten", acViewPreview, , strWhere
    Exit_Command9_Click:
    Exit Sub
    Err_Command9_Click:
    MsgBox Err.Description
    Resume Exit_Command9_Click

    End Sub



    Thanks again for any help you're willing to give me! I really appreciate this!

  12. #12
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Well, there's nothing there that would filter anything, unless strWhere is set elsewhere. It's used here, but never given a value.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  13. #13
    NewbyForAccess is offline Advanced Beginner
    Windows 7 64bit Access 2003
    Join Date
    Sep 2015
    Posts
    49
    I had the code in for my dates being pulled from my main form. I've since removed them because we decided at work today to keep an ongoing record so no dates will be used. The report is working perfectly! Thank you so much for your help. I plan to study more from your web site. I have much to learn!

  14. #14
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  15. #15
    NewbyForAccess is offline Advanced Beginner
    Windows 7 64bit Access 2003
    Join Date
    Sep 2015
    Posts
    49
    Okay, everything is working fine with this except one big issue that I ran across today. Now what I'm seeing is in the detail section of my report where I'm calculating my percentage in a textbox with this formula:

    [scrap pcs]/[good pcs]+[scrap pcs]

    It works except now I see that I'm getting a #Num value in my scrap % textbox when both scrap pcs and good pcs contain the values of 0. I'd like to get this error code removed without affecting the calculations for all other records in the report. I know it's because of the division by 0 issue. I've tried every combination of things I've seen posted on the net and can't find anything that seems to work for me. I was so sure I could figure this one out since I'm very familiar with this in Excel, but nothing is working. Any ideas?

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Report Sorting and Grouping
    By singleton2330 in forum Database Design
    Replies: 4
    Last Post: 10-16-2014, 11:07 AM
  2. Report Sorting
    By B30 in forum Reports
    Replies: 1
    Last Post: 10-07-2014, 12:28 PM
  3. Sorting a report
    By tylerg11 in forum Reports
    Replies: 1
    Last Post: 12-14-2012, 03:25 PM
  4. Sorting numbers on a report
    By paul123 in forum Access
    Replies: 6
    Last Post: 02-15-2012, 03:34 PM
  5. Incorrect sorting in report.
    By jonesy29847 in forum Reports
    Replies: 2
    Last Post: 06-16-2010, 05:56 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