Tải bản đầy đủ - 0 (trang)
Hack 30. Use Conditional Formatting to Point Out Important Results

Hack 30. Use Conditional Formatting to Point Out Important Results

Tải bản đầy đủ - 0trang

backgroundcolorpropertieswhenaspecifiedconditionismet.

Figure4-11showstheConditionalFormattingdialogbox.In

thisexample,expressionshavebeenenteredfortheconditions.

Alternatively,youcanbasetheconditionsonactualdatavalues.



Figure4-11.Fontcolorsthatchangebasedonthe

condition



UsetheFormat ConditionalFormatting…menutodisplaythe

ConditionalFormattingdialogbox.TheConditionalFormatting

dialogboxmanagesformattingforonecontrolatatime.

Therefore,youmustselectacontrolbeforeyoucanaccessthe

menu.Also,themenuitemisdisabledunlessconditional

formattingcanbeappliedtotheselectedcontrol.

Figure4-11showstheconditionalformattingthathasbeenset

upforthetxtCT2004Totaltextbox.Inparticular,forthiscontrol

thefollowingthreeformattingoptionshavebeenset,totestfor



thedifferenceinpercentagebetweenthe2003and2004

amounts:



Greaterthan20%

([txtCT2004]-[txtCT2003])/[txtCT2003]>0.2



Greaterthan15%andequaltoorlessthan20%

([txtCT2004]-[txtCT2003])/[txtCT2003]<=0.2And

([txtCT2004]-[txtCT2003])/[txtCT2003]>0.15



Greaterthan10%andequaltoorlessthan15%

([txtCT2004]-[txtCT2003])/[txtCT2003]<=0.15And_

([txtCT2004]-[txtCT2003])/[txtCT2003]>0.1



Eachconditionprovidesdifferentformattingbasedonselections

madeintheConditionalFormattingdialogbox.Thisworksfine,

butthethree-conditionlimitmightrequireanotherapproach.



4.4.2.ConditionalFormattingtheVBAWay

Byplacingcodeintothereport'seventstubs,youcanprovide

robustformattingbeyondwhatthestandardconditional

formattingfeatureallows.Thestandardformattinghastwo

majorlimitations:youcantestforthreeconditionsonly,and



someoftheformattingoptionsaren'tavailable.

TheworkaroundistojustcodeupyourownusingVBA.Figure

4-12showsthereport;notethatTotalVisitsfor2004issetin

italicandhasaborderaroundit.



Figure4-12.Conditionalformattingapplied

throughVBAcode



Thisformattingwasappliedbecauseaconditionwasmet,based

onwhatwastestedinthecode.Thiscodehasbeenplacedin

thereport'sReportFooter_Printevent:



PrivateSubReportFooter_Print(CancelAsInteger,PrintCountAs

Dimvisits_changeAsSingle

visits_change=([txt2004Total]-[txt2003Total])/[txt2003T

SelectCasevisits_change



CaseIs>0.25

Me.txt2004Total.Properties("ForeColor")=vbBlue

Me.txt2004Total.Properties("Borderstyle")=1

Me.txt2004Total.Properties("BorderColor")=vbBlack

Me.txt2004Total.Properties("FontItalic")=1

CaseIs<=0.25,Is>0.2

Me.txt2004Total.Properties("ForeColor")=vbBlue

CaseIs<=0.2,Is>0.15

Me.txt2004Total.Properties("ForeColor")=vbGreen

CaseIs<=0.15,Is>0.1

Me.txt2004Total.Properties("ForeColor")=vbMagenta

CaseIs<=0.1,Is>0

Me.txt2004Total.Properties("ForeColor")=vbBlack

CaseIs<=0

Me.txt2004Total.Properties("Borderstyle")=1

Me.txt2004Total.Properties("BorderColor")=vbRed

EndSelect

EndSub



ThecodeteststhepercentagechangeandthenusesaSelect

Casestatementtoapplydifferentformattingbasedonthe

percentagechange.Sixconditionsareprovided,butyouaren't

limitedintermsofnumberofconditions;usewhatevernumber

makessenseforyourapplication.Also,thetypeofformattingis

opentowhateveryoucancontrolthroughVBA,whichisjust

abouteverything.



Hack31.ProvideaDirectLinktoaReport



Provideadesktopshortcuttoareportsothatuserscan

completelyskiptheprocessofstartingupthedatabase.

Whatcanbeeasierforamanageroradatabase-challenged

individualthanjustskippingtheprocessofopeningthe

database?Youcaneasilyprovidethisfunctionalitybyincluding

ashortcutdirectlytothereport.Theshortcutgoesontheuser's

desktop.



4.5.1.CreatingaShortcut

Tocreatesuchashortcut,firstopenthedatabase,andthen

right-clickthedesiredreport.Thecontextmenuincludesa

CreateShortcut…menuitem,asshowninFigure4-13.

WhentheuserclickstheCreateShortcut…menuitem,adialog

boxpopsupforhertoselectwheretoplacetheshortcut.The

user'sPCdesktopwillprobablybefilledinasthedefault,as

showninFigure4-14.

AftertheuserclickstheOKbutton,thedesiredshortcutis

created.Clickingtheshortcutstartsupthedatabaseandopens

thereport,butunfortunately,thedatabasestaysopen.



Figure4-13.Creatingashortcuttoareport



Figure4-14.Selectingthelocationforthe

shortcut



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Hack 30. Use Conditional Formatting to Point Out Important Results

Tải bản đầy đủ ngay(0 tr)

×