Solved

Populate report with OpenArgs with Grouping

Posted on 2013-11-12
9
317 Views
Last Modified: 2013-11-12
Hello,

I pass a SQL statement to a report  like this:

"Select [Date], [DateClosed],[MDR], [ShipperId], [ScrapCode], [Program], [PartNumber], [PartName], [QTY],[PartCost],[EXTCost], [Supplier], [MDRClosed] from tblSupplierDebitSummary  Where [Date] Between #" & Me.Start_Date.Value & "# and #" & Me.End_Date.Value & "# GROUP BY [Supplier], [MDR],  [Date], [DateClosed], [ShipperId], [ScrapCode], [Program], [PartNumber], [PartName], [QTY],[PartCost],[EXTCost], [MDRClosed] ORDER BY Suppler;"


DoCmd.OpenReport "New Supplier Debit Summary", acViewPreview, , , , strSQL

Open in new window




And on the report I do this:

If Not IsNull(Me.OpenArgs) Then
 Me.RecordSource = Me.OpenArgs
 End If


This all works great. Now I need to Group By Supplier and MDR and page each distinct supplier to a its own page. Hope that makes sense.

I have tried this approach but it does not work:
I have seen that you can right click on the report detail and choose sorting and grouping. I have tried that but get and error that supplier is invalid. I presume this is because the report does not know about the data?


Is there a way to do grouping, sorting and paging in VBA?
0
Comment
Question by:gogetsome
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 39642290
Try this...

Set the recordsource of your report to this query (no criteria)

Select [Date], [DateClosed],[MDR], [ShipperId], [ScrapCode], [Program], [PartNumber], [PartName], [QTY],[PartCost],[EXTCost], [Supplier], [MDRClosed] from tblSupplierDebitSummary ORDER BY  [Supplier], [MDR],  [Date], [DateClosed], [ShipperId], [ScrapCode], [Program], [PartNumber], [PartName], [QTY],[PartCost],[EXTCost], [MDRClosed]

Then set the grouping and sorting in your report as needed

Remove the reports Open Event code that sets the recordsource based on Open Args.

And change the code that opens the report to this:

Dim strSQL as string
 strSQL =  "[Date] Between #" & Me.Start_Date.Value & "# and #" & Me.End_Date.Value & "#"
DoCmd.OpenReport "New Supplier Debit Summary", acViewPreview, WhereCondition := strSQL

Open in new window

0
 

Author Comment

by:gogetsome
ID: 39642336
Thank you mbizup for your assistance. Everything seems logical and works up to the last change.
these controls are not on the report and are on another form

 strSQL = "[Date] Between #" & Me.Start_Date.Value & "# and #" & Me.End_Date.Value & "#"
0
 
LVL 61

Expert Comment

by:mbizup
ID: 39642352
Ok - that block of code should go on the form that opens the report (not in the report itself)
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 39642364
Commenting the code so that it is clearer (it should be in something like a button click event on the form where the user picks the dates):


Dim strSQL as string
' Define the criteria, based on the dates the user has chosen on this form
 strSQL =  "[Date] Between #" & Me.Start_Date.Value & "# and #" & Me.End_Date.Value & "#"

' Open the report, based on the above criteria (the WhereCondition parameter)
DoCmd.OpenReport "New Supplier Debit Summary", acViewPreview, WhereCondition := strSQL

Open in new window

0
 

Author Comment

by:gogetsome
ID: 39642392
Yes, the code works perfectly and much better than how I was rendering the report. Now I can take advantage of the sorting and grouping and keeptoghether. AWESOME!

One more question, I have sorting and grouping by supplier, but each row in the result set get it's own page. I need to have a page for each supplier. Can you see by my setting what I did wrong? OR is there another place I need to adjust to accomplish my goal?sorting and grouping settings
0
 

Author Closing Comment

by:gogetsome
ID: 39642519
I figure it out! Thank you so much for your help.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 39642520
Off hand, the settings look okay.  Can you post a sample database, with any sensitive data removed or masked?

I will be out for several hours, but if you need a quicker response, go ahead and post that as a new question.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 39642522
Good for you!  Can you post what you did?
0
 

Author Comment

by:gogetsome
ID: 39642539
By the image above I added a group header then selected the group header and set the Force New Page to Before Section in the properties window. Works like a champ.
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question