title: MS Access Subreport Grouping and Sorting Issues
body: <p>been pulling my hair out with this one.  Searched everywhere and can't get anythign to work.  Here's my scenario:</p>
  
  <p>I have a report with several subreports from linked tables. I would like to group the subreports to sort on a given field based on the value of a variable called SORT_BY, and force a page break for each value., i.e. Group a subreport on ItemDescription or ItemLocation.  The SORT_BY variable is set from a users prefs dialog. (ya, I'm using it like a constant but the user can change it)</p>
  
  <p>Now, I want the user to be able to preview the report before they print.  I have the report being launched in ReportView mode.  This allows me to place a "Print" button and a "Close" button in the header of the report (which do not print).  I have it set this way because the user is locked out of the normal "ribbon" and other controls so I have to provide buttons.  The buttons do not show up in PrintPreview mode.  </p>
  
  <p>Obviously, I need to accomplish this via VBA.  I can't seem to get GroupLevel settings to work.  I've tried a CreateGroupLevel function to no avail.  Tried with existing groups and with no existing groups.  I've tried abandoning the group idea and simply tried to Sort the subreports using the OrderBy property, and nothing works.  I'm going crazy.</p>
  
  <p>Does anyone have any suggestions... other than giving up? :-)</p>
  
  <p><em><strong></em></strong> UPDATE:
  I've been trying the CreateGrouplevel function before opening the main report.  i.e. open each subreport in design view, add the group, close the subform, then open the main report.  However, when I try to implement the CreateGroupLevel function, I get the error:</p>
  
  <p>Run-time error '2154':
  You can't call this function when the Group, Sort, and Total Pane is open.</p>
  
  <p>I don't understand this.  Here is my code:</p>
  
  <pre><code>DoCmd.OpenReport strReport, acViewDesign
  intGroupLevel = CreateGroupLevel(strReport, "FluorescentDescription", True, False)
  DoCmd.Close acReport, strReport
  </code></pre>
  
  <p>Thoughts?</p>
  
  <p>OOOPS!</p>
  
  <p>Ok, so I figured out te '2154' error.  Silly really, if you have EVER turned on the Group, Sort, Total Pane while editing a report, it will automatically be turned on every time you enter Design View on that report until you physically turn it off.  Strange.  Still chipping away at this.</p>