<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
Thursday, August 16, 2007

Highlighting Reports

Analysis of data stored in Tables and providing resultant information in the form of Reports to the outside world is an important function of any Database Management System.

An Access Application may contain several Tables logically related but maintained separately for easier handling. When it is time to prepare Reports related tables are selected and joined on common information in them, filtered and placed the output on Reports. Meaningful and timely Reports play a very important roll in decision making.

Report designing is an Art in its own merit, like Form designing. MS-Access is equipped with excellent Report Designing Tools and with little practice you can master it.

We have been asked to prepare a report on the Company’s Sales Team, to review their monthly Sales Target Achievement. A mandatory Target Amount of $100,000 is fixed on each member of the Team and the Management wants a month-end Report to review his or her performance. The management focuses on the performance of the Sales Team every month and if any member of the Team lags behind the Target, they have to undergo a postmortem to set things right for the future.

We have prepared a sample Report on the Sales Team's Month-end figures, highlighting cases that didn’t meet the stipulated Target Amount of $100,000, with a red circle around them.

The finished Report image is given below:

Report Image

The tabular Report above is designed with the Report Wizard and nothing special about it except highlighting of Values less than $100,000 with a circle around them. A small VB Routine in the Detail_Print() Event Procedure compares value on each row with the target figure of $100,000 when the printing/print previewing is in progress and if any of them is less than $100,000 then draws a red circle around that Value.

To prepare this report we need two Tables from the Northwind.mdb database. If you are not sure where the file can be located, visit the earlier Post: Saving Data on Forms not in Table for the location reference of the Northwind.mdb database. Import the following two Tables from the Northwind.mdb database.


  • Orders

  • Order Details


  1. Click on the Query Tab in the Database Window.

  2. Click New to create a new Query and click Close button on the Show Table dialog control to close it without selecting a Table from the list.

  3. Click on the Toolbar button with the SQL label on it to display the Query’s SQL Window.

  4. Copy and paste the following SQL String into the SQL window and save it with the Query Name: SalesReportQ0.


  5. SELECT Orders.OrderID, Orders.EmployeeID,
    [Order Details].UnitPrice, [Order Details].Quantity,
    [UnitPrice]*[Quantity] AS Extended_Price
    FROM Orders INNER JOIN [Order Details]
    ON Orders.OrderID = [Order Details].OrderID;

  6. Go through steps 2 & 3 above, to create another Query from the source data of the first Query SalesReportQ0, Copy and Paste the following SQL String into the Query's SQL Window and save it with the Name:SalesReportQ


  7. SELECT SalesReportQ0.EmployeeID,
    Sum(SalesReportQ0.Extended_Price) AS Total
    FROM SalesReportQ0
    GROUP BY SalesReportQ0.EmployeeID;
  8. Click on the SalesReportQ Query and select Report from the Insert Menu. Select Auto Report: Tabular on the Report Wizard and make changes to the design to look like the sample image given below:



  9. Report Design View Image

  10. Click on the Total Field and display the Property Sheet. Change the following Property Values:


  11. Name : Total
    Border Color : 12632256

  12. Display the VB Module of the Report, click on the Code Toolbar Button above or select Code from View Menu.

  13. Copy and paste the following Code into the VB Module of the Report:


  14. ‘Global declaration.
    ‘The next line (Dim MinTarget As Double, curVal As Double)
    ‘must be placed just below the Option Compare Database line
    ‘ (and Option Explicit line, if present) at top of the Form Module.


    Dim MinTarget As Double, curVal As Double


    Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
    ' Draw ellipse around controls that meet specified criteria.
    Dim ctl As Control, ctl2 As Control, intPrintCircle As Boolean
    Dim sngAspect As Single, sngYOffset As Single
    Dim intEllipseHeight As Integer, intEllipseWidth As Integer
    Dim sngXCoord As Single, sngYCoord As Single


    On Error GoTo Detail_Print_Err


    MinTarget = 100000
    curVal = Me![Total]
    If curVal < MinTarget Then
    intPrintCircle = True
    Else
    intPrintCircle = False
    End If

    'slightly increase/decrease this value
    'to adjust the oval shape.

    sngAspect = 0.3

    'Determine height and width of ellipse.

    intEllipseHeight = Me.Total.Height
    intEllipseWidth = Me.Total.Width
    sngYCoord = Me.Total.Top + (intEllipseHeight \ 2)


    Set ctl2 = Me.Total
    If Not IsNull(ctl2) Then
    Set ctl = ctl2

    'Determine coordinates of ctl and draw ellipse.

    If intPrintCircle Then
    sngXCoord = ctl.Left + (intEllipseWidth \ 2)
    Me.Circle (sngXCoord, sngYCoord), intEllipseWidth \ 2, _
    RGB(255, 0, 0), , , sngAspect
    intPrintCircle = False
    End If
    End If


    Detail_Print_Exit:
    Exit Sub


    Detail_Print_Err:
    MsgBox Err.Description, , "Detail_Print"
    Resume Detail_Print_Exit
    End Sub

  15. Save the report with the Name: Sales Report.

  16. Open the report in Print Preview to see how it works. The Circle is drawn based on the size of the Total Textbox. If the control is too wide then upper and lower parts of the elliptical shape may not appear within the control boundary. To correct this problem you can reduce the width of the Total Field, if it is too wide, or you may reduce the value in sngAspect = 0.3 in the program into say 0.25. You may increase or decrease this value and try out to perfectly fit the elliptical shape within the textbox boundaries.


If you prefer Color Coding the Sales Values, rather than struggling with the above technique, then there is an easier way to do it known as Conditional Formatting (MS-Office 2000 or later).

Let us say, we want all values above $100,000 should appear in Green Color, below $100,000 in Red and all $100,000s should print in normal Color. Sample image is given below:



Report Image with Color Coding


  1. Make a copy of the Sales Report and delete the Code from the VB Module.

  2. Click on the Total textbox in Design View.

  3. Select Conditional Formatting… from the Format Menu.

  4. Set the conditions and the Color as shown below:



  5. Conditional Formatting Control Image

  6. After setting the first condition click Add>> to expand the control down to set more conditions. Up to three conditions you can set on the same field with different Formats. After setting the values click OK to save the changes.

  7. Open the Report in Print Preview to display the Values in different colors based on the conditions that we set on the control.

There are situations that we cannot use the conditional formatting method and need to go by the drawing the elliptical shape method. In both examples given above we are comparing individual values to a constant ($100,000) and then draws a circle or changes color with conditional formatting.

Assume that we are running a Service Station and we have Service Contracts with Companies for servicing their vehicles regularly for a certain period of time or the Vehicle’s Odometer reading reaches a certain level. Till that time the Vehicle comes for servicing on a fixed interval of 3 months or after every 5000 KMs etc.

The management asks us to prepare a Report on all Vehicles on Service Contracts showing Date of Service, Odometer Reading & the Expenses. The Report is sorted on Service Date and if there is any Odometer recording found in Error (i.e. the meter reading is recorded less than the earlier service-time recording) that must be highlighted on the Report to quickly identify them for investigation. It can be tampering of the meter or it can be recorded wrongly by the Servicing personnel. In either case it should be highlighted.

In this case, we have to compare each value with the previous meter reading and if the current value is found less than the previous one then it must be highlighted with a circle. There may be repetition of lesser values further then we have to continue putting circles around all those values till we reach a value greater than the one that we are holding as key. In these kind of situations the conditional formatting method cannot be used.





Download Demo Database




Startup Screen Design
Animated Floating Calendar
Edit Data in Zoom-in Control

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