Tải bản đầy đủ - 0 (trang)
Hack 91. Automatically Check for Database Table Updates

Hack 91. Automatically Check for Database Table Updates

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

dateofthetablesinthemasterdatabasewiththerecordsin

thetblTableVersionstable.

Youmightwonderwhywedon'tjustcomparethemodified

datesofthetablesthemselvesinthelocaldatabase.Whyisa

tablekeptwiththemodifieddates?Thereasonisasafeguard:

usersmightalterthetableslocally,therebychangingthelast

modifieddateonlocaltables.Thepointistocheckifthemaster

databasecontainsupdatedtablesthathavenotbeenusedyet.

ThedatesinthelocaltblTableVersionstablearethemodified

datesoftablesinthemasterdatabasefromthelasttimeany

particulartablewascopied.

Figure8-37showsthetblTableVersionstable.Twotableshave

datesthatareinDecember2004.



Figure8-37.Keepingtrackofthelastmodified

date



8.21.2.TheCode

Whenthelocaldatabaseopens,theAutoExecmacrocallsthe

followingget_updatesfunction,whichthereforerunsupon

startup:



Functionget_updates()

OnErrorGoToerr_end

Dimupdate_dbAsString

update_db="G:\UpdateDB.mdb"



DimcatAsNewADOX.Catalog

DimtblAsNewADOX.Table

DimconnAsADODB.Connection

Setconn=CurrentProject.Connection



Dimlocal_tblAsString

Dimcurrent_object_dateAsDate

'Openthecatalog

cat.ActiveConnection="Provider=Microsoft.Jet.OLEDB.4.0;"&_

"DataSource="&update_db

ForEachtblIncat.Tables

IfLeft(tbl.Name,4)<>"MSys"Then

current_object_date=_

DLookup("[ModifiedDate]","tblTableVersions",_

"[TableName]='"&tbl.Name&"'")

Iftbl.DateModified>current_object_dateThen

DoCmd.DeleteObjectacTable,tbl.Name

DoCmd.TransferDatabaseacImport,"MicrosoftAccess",_

update_db,acTable,tbl.Name,tbl.Name

'storenewdate

conn.Execute("UpdatetblTableVersionsSetModifiedDate

tbl.DateModified&"#WhereTableName='"&tbl.Name

EndIf

EndIf

Next

Setcat=Nothing

Setconn=Nothing

MsgBox"done"

ExitFunction

err_end:



MsgBoxErr.Description

EndFunction



8.21.3.RunningtheCode

AmixtureofVBA,ADOX,andADOworkstogethertocheckfor

updates.AnADOXcatalogobjectiscreatedandissettothe

masterdatabaseG:\UpdateDB.mdbinthisexample.Allthe

tablesinthemasterdatabaseareexamined;however,system

tablesaren'tincluded.AllsystemtablesstartwithMSys[Hack

#15].

TheDateModifiedpropertyofeachtableinthemasterdatabaseis

checkedagainstthelocallystoreddateforthesamenamed

tables.Whenitfindsthatamasterdatabasetablehasanewer

modifieddate,DoCmddeletesthetableinthelocaldatabaseand

importsthenewtablefromthemasterdatabase.Then,aSQL

UpdatestatementupdatesthedateforthetableinthetblTableNamestable.

Aftertheroutinecompletes,theusercangoaboutherbusiness

asusual.Theapplicationworksasalwaysbecausethetable

nameshavenotchanged.

Theonlycaveatwiththishackisthatitisusefultoupdate

tablesthatdon'tshareinarelationship.Relatedtablesneedto

havetherelationshipbrokenbeforeyoudeleteandthen

reestablishthem.Therefore,thishackisperfectfortablesthat

containthesourceforlookuplistsorthatdon'tparticipateina

relationship.Youcandevelopadditionalcodetotestfor

relationshipsandhandlethemappropriately.



9.Third-PartyApplications

Section9.1.Hacks9295

Hack92.DocumentYourDatabasewithTotalAccess

Analyzer

Hack93.BuildanApplicationShellwithEZApplication

Generator

Hack94.LoadYourDatabasewithTestData

Hack95.UseAccessasanXMLDatabase



9.1.Hacks9295

MuchofthefocusinAccessbooksinvolveshowtomanage

buildinganapplicationworkingwithtables,queries,forms,and

reportsandapplyingsolutionswithmacrosandcode.However,

onceyou'vecompletedallthatwork,youmightneedatoolto

documentyourdatabase[Hack#92].Similarly,whenyou

createanapplication,youmightnotbeconsideringallthe

management,functionality,andutilitiesthatcangointoyour

database.Fortunately,aproductisavailablethatfleshesthis

outforyou[Hack#93].

Ofcourse,dataisthepointofadatabase.Howoftenhaveyou

designedadatabaseandthenhadtofindsomedatatotestit

with?Youcanenterdatamanually,oryoucanuseaproduct

thatcreatesdataforyou[Hack#94].

Inadditiontoallthis,thischapteralsoshowsyouhowtobuild

anapplicationwithoutanytables."UseAccessasanXML

Database"[Hack#95]showshowtorunanXMLdatabase

fromAccess,readingfromandwritingtoanexternalXMLfile.



Hack92.DocumentYourDatabasewithTotal

AccessAnalyzer



Getthefullnuts-and-boltsskinnyonyourdatabase.

EvenasimpleAccessdatabasehasalotinit.Justtakeatable

ofdata,aform,afewcontrols,andareport,andthenumberof

propertiesisinthehundreds.Alargedatabasehasan

unimaginablenumberofitemsinit.

Now,imagineautilitythatletsyoudrilldownanywhereinyour

databaseanduncovernuggetsofinformationyouprobably

didn'tevenknowabout.EntertheTotalAccessAnalyzerby

FMS,Inc.(http://www.fmsinc.com).Thisoutstandingproduct

tellsyoueverythingaboutyourdatabase.Itleavesnothingout.



9.2.1.RunningtheAnalyzer

AfteryouinstalltheAnalyzer,itisavailableasanadd-in.

Regardlessofwhichdatabaseyouhaveopen,justgotothe

Tools Add-InsmenutofindtheAnalyzer.TheAnalyzerruns

fromamainform,showninFigure9-1.



Figure9-1.TotalAccessAnalyzer



Togetstarted,clicktheDocumentbutton.Thisrunsthe

DocumentationWizard,whichwalksyouthroughselecting

whichitemstodocument.Figure9-2showsthefirstscreenof

theDocumentationWizard.

Aftermakingaselection,clicktheNextbuttontobringupthe

wizard'ssecondscreen,showninFigure9-3.

Onthisscreen,youcanselecttodocumentrelationships,

documentsecurity,andgeneratefieldcrossreferencesthat

showyouwherefieldsareusedthroughoutthedatabase,

amongotherthings.Generatingfieldcrossreferencesisagreat

featurebecausealthoughit'sgoodtogetdetailsaboutafield,

it'sevenbettertoknowwherethefield'sdataispresented(on

formsandreports).

Thedocumentationprocessworksbywritingtheresultstoan

externalfile.Inthethirdwizardscreen,showninFigure9-4,

youcanselectwherethisexternalfilegoes(orjustacceptthe



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

Hack 91. Automatically Check for Database Table Updates

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

×