Tải bản đầy đủ - 0 (trang)
Section 18.  Create Tables Faster

Section 18.  Create Tables Faster

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

InFigure2-22,thedefaultTextfieldsizehasbeenchangedto

100.Thismeansthatasnewtextfieldsareaddedtothedesign

ofatable,theywilldefaulttoasizeof100.Also,thedefault

NumbertypehasbeensettoSingle.Asnewnumberfieldsare

added,theydefaulttotheSingledatatype.Theoveralldefault

fieldtypeissettoNumber;therefore,asnewfieldsareentered

intoatabledesign,theydefaulttoaNumberfieldtypeandthat

typewillbeoftheSinglenumbertype.

Alteringthesedesigndefaultscanbequiteuseful.If,for

example,youaredesigningatablethatpredominantlycontains

dates,setthedefaultfieldtypetoDate/Time,andsaveyourself

alotoffield-typeselection.Asyouenternewfields,theywill

defaulttoDate/Time.Youwillneedtoadjustonlytheminority

offieldsthataren'tofthistype.



2.7.1.SettingDefaultValues

ThesettingsintheOptionsdialogboxcontrolfieldtypesettings

butoffernothingtoindicatedefaultvalues.Inotherwords,you

canselectSingleasthedefaultnumbertype,butyoucan't

specifythatthefielddefaultstoavalueof1.25(forexample)

asnewrecordsareaddedtothetable.

However,asettingisavailableinwhichyoucanindicatea

defaultvalue.Thefieldinthethirdrowofthetablebeing

designedinFigure2-23hasbeenmanuallysetto1.25,andthis

becomesthedefaultvalueforthefield.



Figure2-23.Settingadefaultfieldvalue



2.7.2.TheCode

Whatif100otherfieldsneedtobesettosuchadefaultvalue?

Myfingershurtjustthinkingaboutthemanualentrythatwould

beinvolved!Automatingthistaskwillbealifesaverwell,atleast

afingersaver.Alittlecodetotherescue!



Subchange_field_defaults()

DimcatAsADOX.Catalog

Setcat=NewADOX.Catalog

DimfldAsADOX.Column

cat.ActiveConnection=CurrentProject.Connection

ForEachfldIncat.Tables("myNewTable").Columns

Iffld.Type=adSingleThen

fld.Properties("Default").Value=1.25

EndIf

Next

Setcat=Nothing

EndSub



ThiscodeusestheADOXlibrary[Hack#17]toworkwiththe

fieldsinthedesignatedtable.Inthisexample,thetablename

ishardcoded,butitcertainlycanbepassedasanargument.

Thiscodeexamplecyclesthroughthefields,andwhenafield

typeisdesignatedasSingle(indicatedbytheadSingleconstant),

itsdefaultvalueissetto1.25.

Youcanexpandthiscoderoutinetosetdefaultvaluesforall

possiblefieldtypes.Evenmore,youcansetdefaultvaluesfor

combinationsoffieldtypesandfieldnames.Forexample,a

fieldnamedlocal_ratecanbeasinglefieldtype,whichyoucan



setittoadefaultvalueof.25;likewise,youcabsetafield

namednational_rate,alsoaSingledatatype,tohaveadefault

valueof.5.



3.EntryandNavigation



3.1.Hacks1927

Anapplication'ssuccessoftenrestsonuseracceptance.With

thisinmind,itmakessensetoplanhowtomakeyour

application'sfront-endexperienceasvisuallypleasinganduserfriendlyaspossible.

Sometimesuserexperienceisoverlooked.Developerscan

spendoodlesoftimedesigningfieldsandtables,settingup

relationships,writingtrickySQL,andsoon.Doesthismean

anythingtothetypicaluser?Notonewhit!

Let'sfaceit.Accessismorethanjustadatabase.Itisa

databasewithbuilt-infront-endtools.Tablesarethecoreofa

database,buttheabilitytocreateformsandreportsisthemain

jobofadevelopmentplatform.Accesshasboth,solet'smake

thebestofboth.

Thehacksinthischapterhavebeendrummedupwiththe

ordinaryuserinmind.Enteringdataisamajoruseractivity,

andthesehacksmakethisoftenmind-numbingactivityalittle

morepleasant.



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

Section 18.  Create Tables Faster

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

×