56
Microsoft Access 2013 ® ® Tutorial 5 Creating Advanced Queries and Enhancing Table Design

Tutorial 5 Creating Advanced Queries and Enhancing …home.ku.edu.tr/.../indr481_fall2015/indr481_fall2015_tutorial5.pdf · Tutorial 5 Creating Advanced Queries and ... – Use the

Embed Size (px)

Citation preview

Microsoft Access 2013® ®

Tutorial5CreatingAdvancedQueriesand

EnhancingTableDesign

XPXPXPObjectives• Session5.1– Reviewobjectnamingstandards– UsetheLike,In,Not,and&operatorsinqueries– FilterdatausinganAutoFilter– UsetheIIffunctiontoassignaconditionalvaluetoacalculatedfieldinaquery

– Createaparameterquery

NewPerspectivesonMicrosoftAccess2013 2

XPXPXPObjectives(Cont.)• Session5.2– Usequerywizardstocreateacrosstabquery,afindduplicatesquery,andafindunmatchedquery

– Createatopvaluesquery

NewPerspectivesonMicrosoftAccess2013 3

XPXPXPObjectives(Cont.)• Session5.3– Modifytabledesignsusinglookupfields,inputmasks,anddatavalidationrules

– Identifyobjectdependencies– ReviewaLongTextfield’sproperties– Designateatrustedfolder

NewPerspectivesonMicrosoftAccess2013 4

XPXPXPCreatingAdvancedQueriesandEnhancingTableDesign• Case- ChathamCommunityHealthServices

Making theClinicDatabaseEasiertoUse

• UserisinterestedintakingbetteradvantageofthepowerofAccesstomakethedatabaseeasiertouseandtocreatemoresophisticatedqueries

• Useralsoneedsasummarizedlistofinvoiceamountsbycity

NewPerspectivesonMicrosoftAccess2013 5

XPXPXPCreatingAdvancedQueriesandEnhancingTableDesign(Cont.)

NewPerspectivesonMicrosoftAccess2013 6

XPXPXPCreatingAdvancedQueriesandEnhancingTableDesign(Cont.)

NewPerspectivesonMicrosoftAccess2013 7

XPXPXPReviewingtheClinicDatabase

• TheNavigationPanedisplaystheobjectsgroupedbyobjecttype– Eachobjectnamehasaprefixtag—atblprefixtagfortables,aqryprefixtagforqueries,afrmprefixtagforforms,andarptprefixtagforreports

– Allthreecharactersineachprefixtagarelowercase.Thewordimmediatelyafterthethree-characterprefixbeginswithanuppercaseletter

– Usingobjectprefixtags,youcanreadilyidentifytheobjecttype,evenwhentheobjectshavethesamebasename

– Objectnameshavenospaces,becauseotherdatabasemanagementsystemsdonotpermitmakingiteasyduringconversionstothosesystems

NewPerspectivesonMicrosoftAccess2013 8

XPXPXPUsingPatternMatchinaQuery

NewPerspectivesonMicrosoftAccess2013 9

• Apatternmatchselectsrecordswithavalueforthedesignatedfieldthatmatchesthepatternofasimpleconditionvalue

• TheLikecomparisonoperatorselectsrecordsbymatchingfieldvaluestoaspecificpatternthatincludesoneormoreofthesewildcardcharacters:asterisk(*),questionmark(?),andnumbersymbol(#)– Theasteriskrepresentsanystringofcharacters,thequestionmarkrepresentsanysinglecharacter,andthenumbersymbolrepresentsanysingledigit

XPXPXPUsingPatternMatchinaQuery(Cont.)

NewPerspectivesonMicrosoftAccess2013 10

XPXPXPUsingaList-of-ValuesMatchinaQuery

NewPerspectivesonMicrosoftAccess2013 11

• Alist-of-valuesmatchselectsrecordswhosevalueforthedesignatedfieldmatchesoneoftwoormoresimpleconditionvalues– CouldincludeseveralOrconditionsinthedesigngrid,butthereisaneasierandclearerwaytodothis• TheIncomparisonoperatorletsyoudefineaconditionwithalistoftwoormorevaluesforafieldthatselectandincludethoserecordinthequeryresults

XPXPXPUsingtheNotLogicalOperatorinaQuery

NewPerspectivesonMicrosoftAccess2013 12

• TheNotlogicaloperatornegatesacriterionorselectsrecordsforwhichthedesignatedfielddoesnotmatchthecriterion

XPXPXPUsinganAutoFiltertoFilterData

NewPerspectivesonMicrosoftAccess2013 13

• YoucanusetheAutoFilterfeaturetochooserestrictionsfasterandwithmoreflexibilitythanusingtheconditionandOrlogicaloperator

XPXPXPUsinganAutoFiltertoFilterData(Cont.)

NewPerspectivesonMicrosoftAccess2013 14

XPXPXPAssigningaConditionalValuetoaCalculatedField• NullFieldsarefieldsinarecorddoesnotcontainanyinformationatall

• Afieldinarecordthatcontainsanydataatall—evenasinglespace—isnonnull– TocombinenonnullLastNameandFirstNamefields,youcanusetheexpressionLastName&“,“&FirstName• The&(ampersand)operatorisaconcatenationoperatorthatjoinstextexpressions

• Concatenation referstojoiningtwoormoretextfieldsorcharactersencapsulatedinquotes

NewPerspectivesonMicrosoftAccess2013 15

XPXPXPAssigningaConditionalValuetoaCalculatedField(Cont.)• TheIIf(ImmediateIf)functionassignsonevaluetoacalculatedfieldorcontrolifaconditionistrue,andasecondvalueiftheconditionisfalse– TheIIffunctionhasthreeparts:aconditionthatistrueorfalse,theresultwhentheconditionistrue,andtheresultwhentheconditionisfalse

– EachpartoftheIIffunctionisseparatedbyacomma– TheIsNullfunctiontestsafieldvalueoranexpressionforanullvalue;ifthefieldvalueorexpressionisnull,theresultistrue;otherwise,theresultisfalse

NewPerspectivesonMicrosoftAccess2013 16

XPXPXPAssigningaConditionalValuetoaCalculatedField(Cont.)

NewPerspectivesonMicrosoftAccess2013 17

XPXPXPAssigningaConditionalValuetoaCalculatedField(Cont.)

NewPerspectivesonMicrosoftAccess2013 18

XPXPXPAssigningaConditionalValuetoaCalculatedField(Cont.)

NewPerspectivesonMicrosoftAccess2013 19

XPXPXPAssigningaConditionalValuetoaCalculatedField(Cont.)

NewPerspectivesonMicrosoftAccess2013 20

XPXPXPAssigningaConditionalValuetoaCalculatedField(Cont.)

NewPerspectivesonMicrosoftAccess2013 21

XPXPXPCreatingaParameterQuery• Aparameterquerydisplaysadialogboxthatpromptstheusertoenteroneormorecriteriavalueswhenthequeryisrun– Thevalueenteredintothepromptcausesthequerytoselectonlythoserecordswithfieldvaluefromthetable

NewPerspectivesonMicrosoftAccess2013 22

XPXPXPCreatingaParameterQuery(Cont.)

NewPerspectivesonMicrosoftAccess2013 23

XPXPXPCreatingaMoreFlexibleParameterQuery

NewPerspectivesonMicrosoftAccess2013 24

• Mostuserswantaparameterquerytodisplaytherecordsthatmatchtheparametervaluetheuserentersortodisplayallrecordswhentheuserdoesn’tenteraparametervalue– Toprovidethisfunctionality,youcanchangethevalueintheCriteria

boxinthedesigngridforthespecifiedcolumn– PrefixtheLikeoperatortotheoriginalcriterionandconcatenatethe

criteriontoawildcardcharacter

XPXPXPAdvancedQueryWizards

NewPerspectivesonMicrosoftAccess2013 25

XPXPXPCreatingaCrosstabQuery

NewPerspectivesonMicrosoftAccess2013 26

XPXPXPCreatingaCrosstabQuery(Cont.)

NewPerspectivesonMicrosoftAccess2013 27

XPXPXPCreatingaCrosstabQuery(Cont.)

NewPerspectivesonMicrosoftAccess2013 28

• ThequickestwaytocreateacrosstabqueryistousetheCrosstabQueryWizard

XPXPXPCreatingaCrosstabQuery(Cont.)

NewPerspectivesonMicrosoftAccess2013 29

XPXPXPCreatingaCrosstabQuery(Cont.)

NewPerspectivesonMicrosoftAccess2013 30

XPXPXPCreatingaFindDuplicatesQuery

NewPerspectivesonMicrosoftAccess2013 31

• Afindduplicatesqueryisaselectquerythatfindsduplicaterecordsinatableorquery– YoucancreatethistypeofqueryusingtheFindDuplicatesQueryWizard

• AfindduplicatesquerysearchesforduplicatevaluesbasedonthefieldsyouselectwhenansweringtheWizard’squestions

XPXPXPCreatingaFindUnmatchedQuery

NewPerspectivesonMicrosoftAccess2013 32

• Afindunmatchedqueryisaselectquerythatfindsallrecordsinatableorquerythathavenorelatedrecordsinasecondtableorquery– UsetheFindUnmatchedQueryWizardtocreatethistypeofquery

XPXPXPCreatingaFindUnmatchedQuery(Cont.)

NewPerspectivesonMicrosoftAccess2013 33

XPXPXPCreatingaTopValuesQuery

NewPerspectivesonMicrosoftAccess2013 34

• Usersmightwanttolimitthenumbertoamoremanageablesizebydisplaying,forexample,justthefirst10records– TheTopValuespropertyforaqueryletsyoulimitthenumberofrecordsinthequeryresults

XPXPXPCreatingaTopValuesQuery(Cont.)

NewPerspectivesonMicrosoftAccess2013 35

XPXPXPLookupFieldsandInputMasks

NewPerspectivesonMicrosoftAccess2013 36

XPXPXPCreatingaLookupField

NewPerspectivesonMicrosoftAccess2013 37

• Dataentryiseasierifusersdonotneedtorememberthecorrectvaluesforfields

• Alookupfieldletstheuserselectavaluefromalistofpossiblevalue

• UseaLookupWizardfieldinAccesstocreatealookupfieldinatable

XPXPXPCreatingaLookupField(Cont.)

NewPerspectivesonMicrosoftAccess2013 38

XPXPXPCreatingaLookupField(Cont.)

NewPerspectivesonMicrosoftAccess2013 39

XPXPXPUsingtheInputMaskWizard

NewPerspectivesonMicrosoftAccess2013 40

• Aliteraldisplaycharacterisaspecialcharacterthatautomaticallyappearsinspecificpositionsofafieldvalue– likehyphensinasocialsecuritynumber– Toincludethesecharacters,youneedtocreateaninputmask,whichisapredefinedformatusedtoenteranddisplaydatainafield

• AneasywaytocreateaninputmaskistousetheInputMaskWizard whichguidesyouincreatingapredefinedformatforafield– YoumustbeinDesignviewtousetheInputMaskWizard

XPXPXPUsingtheInputMaskWizard(Cont.)

NewPerspectivesonMicrosoftAccess2013 41

XPXPXPUsingtheInputMaskWizard(Cont.)

NewPerspectivesonMicrosoftAccess2013 42

XPXPXPUsingtheInputMaskWizard(Cont.)

NewPerspectivesonMicrosoftAccess2013 43

XPXPXPUsingtheInputMaskWizard(Cont.)

NewPerspectivesonMicrosoftAccess2013 44

XPXPXPUsingtheInputMaskWizard(Cont.)

NewPerspectivesonMicrosoftAccess2013 45

XPXPXPIdentifyingObjectDependencies

NewPerspectivesonMicrosoftAccess2013 46

• Anobjectdependencyexistsbetweentwoobjectswhenachangetothepropertiesofdatainoneobjectaffectsthepropertiesofdataintheotherobject– DependenciesbetweenAccessobjects,suchastables,queries,andforms,canoccurasrelationshipsorusingaquerytoobtainvaluesfrommorethanonetable.

– Anyformorreportthatusesfieldsfromaqueryisdirectlydependentonthequeryandisindirectlydependentonthetablesthatprovidethedatatothequery

• TheObjectDependenciespanedisplaysacollapsiblelistofthedependenciesamongtheobjectsinanAccessdatabase

XPXPXPIdentifyingObjectDependencies(Cont.)

NewPerspectivesonMicrosoftAccess2013 47

XPXPXPDefiningDataValidationRules

NewPerspectivesonMicrosoftAccess2013 48

• DefiningFieldValidationRules– Topreventauserfromenteringanunacceptablevalueinafield,youcancreateafieldvalidationrulethatverifiesafieldvaluebycomparingittoaconstantortoasetofconstants• YoucreateafieldvalidationrulebysettingtheValidationRuleandtheValidationTextfieldproperties• TheValidationRulepropertyvaluespecifiesthevalidvaluesthatuserscanenterinafield.• TheValidationTextpropertyvaluewillbedisplayedinadialogboxifauserentersaninvalidvalue

XPXPXPDefiningDataValidationRules(Cont.)

NewPerspectivesonMicrosoftAccess2013 49

XPXPXPDefiningDataValidationRules(Cont.)

NewPerspectivesonMicrosoftAccess2013 50

• DefiningTableValidationRules– Tomakesurethatthevalueauserentersisnotlargerthanthemaximumfieldvalue,youcancreateatablevalidationrule

– UsetheValidationRuleandValidationTextpropertiesandsetthesepropertiesforthetableinsteadofforanindividualfield

– Useatablevalidationrulebecausethisvalidationinvolvesmultiplefields

– Afieldvalidationruleisusedwhenthevalidationinvolvesarestrictionforonlytheselectedfield,anddoesnotdependonotherfields

XPXPXPDefiningDataValidationRules(Cont.)

NewPerspectivesonMicrosoftAccess2013 51

XPXPXPWorkingwithLongTextFields

NewPerspectivesonMicrosoftAccess2013 52

• UseaLongTextfieldtostorelongcommentsandexplanations

• ShortTextfieldsarelimitedto255characters,butLongTextfieldscanholdupto65,535characters– ShortTextfieldslimityoutoplaintextwithnospecialformatting

– LongTextfieldsstoreplaintextsimilartoShortTextfieldsortostorerichtext,whichyoucanselectivelyformatwithoptionssuchasbold,italic,anddifferentfontsandcolors

XPXPXPWorkingwithLongTextFields(Cont.)

NewPerspectivesonMicrosoftAccess2013 53

XPXPXPWorkingwithLongTextFields(Cont.)

NewPerspectivesonMicrosoftAccess2013 54

XPXPXPDesignatingaTrustedFolder

NewPerspectivesonMicrosoftAccess2013 55

• Adatabaseisafile,andfilescancontainmaliciousinstructionsthatcandamageotherfilesonyourcomputerorfilesonothercomputersonyournetwork

• Unlessyoutakespecialsteps,Accesstreatseverydatabaseasapotentialthreattoyourcomputer

• Onespecialstepthatyoucantakeistodesignateafolderasatrustedfolderwhich isafolderonadriveornetworkthatyoudesignateastrustedandwhereyouplacedatabasesyouknowaresafe

XPXPXPDesignatingaTrustedFolder(Cont.)

NewPerspectivesonMicrosoftAccess2013 56