<body><script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener("load", function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <iframe src="http://www.blogger.com/navbar.g?targetBlogID=34083602&amp;blogName=LEARN+MS-ACCESS+TIPS+AND+TRICKS&amp;publishMode=PUBLISH_MODE_FTP&amp;navbarType=BLUE&amp;layoutType=CLASSIC&amp;searchRoot=http%3A%2F%2Fblogsearch.google.com%2F&amp;blogLocale=en_US&amp;homepageUrl=http%3A%2F%2Fwww.msaccesstips.com%2F" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" height="30px" width="100%" id="navbar-iframe" allowtransparency="true" title="Blogger Navigation and Search"></iframe> <div></div>
www.msaccesstips.com

LEARN MS-ACCESS TIPS AND TRICKS


International Response Fund

LEARN MS-ACCESS TIPS AND TRICKS

↑ Grab this Headline Animator

Your Ad Here
Friday, July 17, 2009

Detail and Summary from same Report

You don't have to design two different Reports; one for Detail Listing of records with Group-wise Totals and another one for Group-wise Totals alone. We can play a small trick to get both outputs from the same Report depending on the User's choice.


Recommended reading before proceeding with this topic:

Hiding Report Lines Conditionally
Hiding Records and Group Footer Calculations
Hiding Group Header/Footer and Detail Sections

For hiding of Report Lines conditionally there are other methods too. For example the following VBA Code (instead of the earlier simple method we have tried) can give you the same result for hiding Detail Section Report Lines:



Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If [OrderID] = 10280 Or [OrderID] = 10297 Then
Report.MoveLayout = False
Report.NextRecord = True
Report.PrintSection = False
Else
Report.MoveLayout = True
Report.NextRecord = True
Report.PrintSection = True
End If

End Sub


We must set all the three Report Property Values shown above in different combinations to get the same result. We have already explored the PrtDevMode, PrtMIP Report Properties and learned how to change Paper Size and Page Orientation, Margin Settings and Column Settings through Program while previewing or sending the Report to a Network Printer.


If you would like to know more details about the above Report Property settings you may search VBA Help Documents. You can get the Help Document related to this topic quickly if you open any Code Module and Type Report.MoveLayout and press F1 while the Cursor is next to the Text or in the Text.


We will continue with our new Trick. We will use a copy of last week's sample Report Order_Details2 for this experiment. If you already have a Report with Group-wise Sub-Totals you may use that too. If you are using your own Report then ensure that you are displaying the Group Item Value or Description along with the label Sub-Total at the left side of the sub-total value control in the Group Footer.


We will hide the Group Header and Detail Sections when the User opens the Report for Summary Preview or Print. A sample Report Image in Design View is given below.



Sample Report Image in Design View


We will replace the Code written for earlier example, with new Program so it is better to make a copy of that Report for our trial run now.


  1. Make a Copy of the Order_Details2 Report and Paste it with the name Order_Details3.

  2. Open the Report in Design View.

  3. Write the Expression =Sum([Quantity]) in the empty Text Box (we have removed this for our earlier example) in the CustomerID Group Footer below the Quantity field in the Detail Section.


  4. Write the same expression in the Report Footer empty Text Box to take Quantity Report level Total.


  5. Display the Code Module of the Report (View - ->Code).

  6. Delete the existing VBA Code from the Code Module (Class Module is the correct Term for Report and Form Modules).


  7. Copy and Paste the following VBA Code into the Module and Save the Report.



Option Compare Database
Dim x_opt As Integer

Private Sub Report_Open(Cancel As Integer)
If IsLoaded("MainSwitchBoard") Then
x_opt = Forms![MainSwitchBoard]![Opt]
Else
x_opt = 1
End If

End Sub

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If x_opt = 2 Then
Cancel = True
Else
Cancel = False
End If

End Sub

Private Sub GroupHeader0_Format(Cancel As Integer, FormatCount As Integer)
If x_opt = 2 Then
Cancel = True
Else
Cancel = False
End If
End Sub


As you can see; the above Code is not that complicated to understand. We are reading the Report Option settings from the MainSwitchBoard in the Report_Open() Event Procedure and loading that value into a Global Variable x_opt (defined at the top of the Module below the Global default declaration Option Compare Database). Using IsLoaded() Function to check whether the MainSwitchboard Form is open or not before attempting to read the Value from the Option Group control from the Form otherwise the Report is open normally for Detail print preview.


Copy the following Code for the IsLoaded() Function and paste it into a Global Module (Standard Module) of your Project and save it:



Public Function IsLoaded(ByVal strForm As String) As Boolean
'***********************************************************
'Checks through the Forms Collection and if the Form is
'loaded in Memory then Returns TRUE else FALSE
'***********************************************************
Dim varFrm As Form

On Error GoTo IsLoaded_Err

IsLoaded = False

For Each varFrm In Forms
If varFrm.Name = strForm Then
IsLoaded = True
End If
Next

IsLoaded_Exit:
Exit Function

IsLoaded_Err:
IsLoaded = False
Resume IsLoaded_Exit
End Function


The IsLoaded() Functions checks through the list of all Open Forms looking for the MainSwitchBoard Form and if it is open then returns TRUE otherwise FALSE.

If the Report output option setting on the Main Switchboard is 1 then the Report will print normally with all Report Sections including the Group Header/Footer Sections.


If the option setting is 2 then the Format Event of Report CustomerID Group Header and Detail Section is cancelled (these Sections are hidden) and shows only the Page Header/Footer, CustomerID Group Sub-Totals and Report Total in Print Preview or Print.


We will create a Report Option Group on the MainSwitchBoard Form (or you may create a new sample Form as shown below) to set and launch our Report from there for Detail and Summary Options.



Main Switchboard Form Image



  1. Open a new Form or your Main Switchboard (Control Screen) Form in Design View.

  2. Check whether the Control Wizard (with the magic wand icon) on the ToolBox is in selected state, if not then select it.

  3. Select the Option Group Tool from the ToolBox.


  4. Draw a rectangle on the Form as shown above. The Option Group Wizard will open up.

  5. Type Detail Report, press TAB Key and Type Summary Report for two options and Click Next.


  6. Accept Detail Report as default choice and Click Finish.


  7. You may drag and position the Child Label attached to the Option Group as shown on the design above and change the Label Caption as Report Options.


  8. Click on the Option Group outer frame to select it and display the Property Sheet (View - -> Properties).


  9. Change the Name Property Value to Opt. (no dot at the end)


  10. Select the Command Button Tool from the ToolBox and draw a Command Button below the Option Group Control.


  11. Display the Property Sheet of the Command Button.


  12. Change the Caption Value to Report Preview.


  13. Set the Hyperlink SubAddress Property value to Report Order_Details3. Don't forget to leave a space between the word Report and your Report Name.


  14. Save the MainSwitchBoard Form.


  15. Open it in normal view. Click on the Report Preview Command Button to open the Report after setting Detail Report or Summary Report Option in the Option Group Control.



NB: Don't forget to close the earlier Report Preview before attempting to open it for different Option.


Next we will explore how to prepare and show Page Totals on each page of the Report.



StumbleUpon Toolbar



InputBox and Simple Menus
Change Form Modes On User Profile
Positioning POPUP Forms
Synchronized Floating Popup Form
Forms and Custom Properties

Labels:

0 Comments:

Post a Comment

Note:Comments subject to Review by Blog Author before displaying.

Links to this post:

Create a Link

<< Home


Creative Commons License
Learn MS-Access Tips and Tricks by msaccesstips.com is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 2.5 India License.



This Page is best viewed with 1280 x 1024 Resolution

   FEATURED LINKS
SITEMAP
Command Button Animation
3D Headings on Forms
MsgBox & Office Assistant
Reminder Ticker
MS-Access & E-Mails
Automated E-Mail Alerts
MsgBox with Options Menu
Colorful Command Buttons
Configure Lotus Notes
Alerts through Network
Running this site has become a costly affair as the revenue from Ads is not sufficient to support it. If you find these pages informative & useful and would like to extend a helping hand, then please do it here.





Link Back to us with this Button

Learn MS-Access

Copy and Paste this HTML Code in your Webpage


Add to Technorati Favorites

Programming Blogs - Blog Catalog Blog Directory
Powered by FeedBurner
Add to Google

Software
Computers blogs
TopOfBlogs




AddMe - Search Engine Optimization Submit Your Site Free!
Go BlogZ Ave Blogs
eBlogzilla Changing LINKS
LS Blogs Blogarama
blog search directory BlogUniverse
Find Blogs in Directory RSS Directory
blogskinny.com ShowcaseBlogs.com
Amfibi

Search Engine Optimization and SEO Tools
Dmegs Web Directory Takeaway for Sale Businesses For Sale
Free Submission Directory Free site submission

Free Listing
 





Free Page Rank Checker

AddThis Social Bookmark Button

Enter your email address:

Delivered by FeedBurner



Top Blogs


Microsoft Access is the Jewell among MS-Office suite of Applications. Its Security features are excellent and works fine in Network environment. MS-Access can link/upload data from any Data Source. Applications that you design should be user-friendly and visually pleasing too. Here I would like to share my experience in Microsoft Access Programming with you and I am sure that you will find them interesting too.

My Photo
Name: Ramachandran Pillai
Location: Cochin, India

I am not an Access Guru and not through MS-Access yet. More to learn and I don’t think that aspect has any end because others have their own style of using this tool. We can learn lot more tricks, other than what we already know, from others too. My programming skills in COBOL, BASIC, Turbo-C, dBase, FoxPro, Visual Basic & Basic HTML attained through self-learning. I wrote my first COBOL Program in 1975 for ICL1901, 3rd Generation Main Frame Computer. Worked as a Computer Operator (NCR VRX8555 Mainframe Machine upto 1990) with M/s. Y.B.A. Kanoo, Saudi Arabia. Started using MS-Access Ver.2 in 1996, when dBase III+ and Foxbase (later version Foxpro) were my favorite DBMS. During Last 13 Year period I have developed more than 45 In-House Applications (medium & small) under MS-Access for our Organization, a leading Automotive Company in Oman. All the Applications are fully Secured and runs under Windows Network. It is my pleasure to share my experience with others. Anything interesting that you would like to share with me, please do. My E-mail Address: aprpillai@msaccesstips.com


If you need a Demo of any of the Topic explained here, send me an E-mail to: aprpillai@msaccesstips.com
with the Topic Description, I shall try to send a sample database to you.


Access Tips | Email | Reports | Report Tricks | Graphs | Forms | Menus | Animation | Security | Internet | How TOs | Linking | Query | Progress Meter | Alerts | Process Tips | Access Functions |




Site Designed by:www.msaccesstips.com