Tải bản đầy đủ - 0 (trang)
Hack 6. Organize and Enhance Your Macros

Hack 6. Organize and Enhance Your Macros

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

isthefirstdayofthemonth(presumablytallyingupfigures

aboutthemonththatjustended).UsingtheDayandNow

functionstakescareoftestingforthefirstdayofthemonth.

TheEmployeeBonusreportrunsonlywhenaconditiontested

withaDLookupfunctionisTRue.

Theunconditionalactionsinthemacroalwaysrun.Evenwhen

theactionswithunmetconditionsarepassedover,themacro

continuestorunanddoesn'tstopprematurely.



1.7.2.CreatingMacroGroups

Macroscanalsobeorganizedintogroups,knownasmacro

groups.Bycreatingmacrogroups,youcanreducethenumber

ofoverallmacrosandkeepsimilarmacroactionstogetherin

oneplace.Thekeydifferencebetweenamacroandamacro

groupistheuseoftheoptionalMacroNamecolumn.

Whenyou'redesigningmacros,usetheViewmenutodisplay

theMacroNamecolumn.Figure1-14showsamacrogroup

namedRunReport.Themacrogrouphandlesthetaskofopeninga

numberofindividualreports.Animportantpoint,though,is

thatthesereportswon'topenatthesametime.Eachmacro

nameexistsasaseparatemacrowithinthelargergroup.



Figure1-13.Usingconditionsinamacro



Figure1-14.UsingtheMacroNamecolumn



Whenaparticularactionneedstobeinitiated,youusethe

nameofthemacrogroup,adotqualifier,andthenameinthe

MacroNamecolumn,likethis:





DoCmd.RunMacro"RunReport.InventoryStatus"



Thepointwheretheactionstartsistherowwiththemacro

name.Successiveactionswillrununtilanothermacronameis

encountered.NotallrowsrequireavalueintheMacroName

column.Thisisthebeautyofmacrogroups.Onecohesive

designhousesanynumberofsmalleractionsets.Thebenefitis

acleanerandeasier-to-managemacroimplementation.



Hack7.RidYourDatabaseofClutter



Implementanobject-uselogtocleanupanoverloaded

databasebyanalyzinguseractionsandthendeleting

never-usedobjects.

SomeAccessdatabaseapplicationsjustgetplainugly.Ifyou

haveeverbrowsedthroughadatabasewithdozensanddozens

offormsandreports,youknowwhatIamreferringto.Thisis

oftentheresultofausercommunityturnedloose:formsfor

everypointandpurpose;areportforeachdayoftheweek;

andthensome.

Addinginsulttoinjury,youcan'teasilytellwhichobjectsthe

usersareactuallyusing.Luckily,thereisawaytoreigninthe

applicationandreducetheclutter.

Thegoalistofindoutwhichobjectsarenolongerbeingused.

Often,userscreateformsorreportsthattheyuseonceand

neverlookatagain.Onceyou'veidentifiedwhichobjectsareno

longerbeingused,youcandeletethemfromthedatabase.This

willlikelyimprovetheperformanceofthedatabaseand

certainlyreduceitsmemoryfootprintafteryoucompactit.The

tricktodeletingunusedobjectsistocreatealistofobjectsthat

arebeingusedandthentodeletetheobjectsthatdidn'tmake

itonthelist.



1.8.1.TrackingObjectUse

Allformsandreportscontainanopenevent.Byputtingasimple

coderoutineintoallopenevents,youcanpopulatealogwiththe

namesoftheobjectsbeingopened.Beforeyoudothis,you



needtocreatealogtabletostoretheobjectnames.This

doesn'tneedtobefancy;indeed,thelogtablecanhavejusta

singlefieldtostorethenames.Optionalfieldscanstorea

timestamp,thetypeofobject,andsoforth.

Figure1-15showsthedesignofsuchatable.Itcomprisestwo

fields:onecapturestheobjectname,andtheothercaptures

theobjecttype.Thetablereceivesarecordeachtimeanobject

isopened.

Toappendarecordtothelogtable,anobjectmusthavealittle

bitofcodeinitsopenevent.Hereisasnippetthatwouldgo

intotheopeneventofaformnamedCustomers:



PrivateSubForm_Open(CancelAsInteger)

DimconnAsADODB.Connection

Setconn=CurrentProject.Connection

DimssqlAsString

ssql="InsertIntotblObjectLogValues('Customers','Fo

conn.Executessql

conn.Close

Setconn=Nothing

EndSub



Figure1-15.Atableforloggingobjectsasthey

areopened



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

Hack 6. Organize and Enhance Your Macros

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

×