tutorial 3 maintaining and querying a...

Post on 11-Jun-2020

1 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Microsoft Access 2013® ®

Tutorial3Maintainingand

QueryingaDatabase

XPXPXPObjectives• Session3.1– Find,modify,anddeleterecordsinatable– Hideandunhidefieldsinadatasheet–WorkintheQuerywindowinDesignview– Create,run,andsavequeries– Updatedatausingaquerydatasheet– Createaquerybasedonmultipletables– Sortdatainaquery– Filterdatainaquery

NewPerspectivesonMicrosoftAccess2013 2

XPXPXPObjectives(Cont.)• Session3.2– Specifyanexactmatchconditioninaquery– Useacomparisonoperatorinaquerytomatcharangeofvalues

– UsetheAndandOrlogicaloperatorsinqueries– Changethefontsizeandalternaterowcolorinadatasheet– Createandformatacalculatedfieldinaquery– Performcalculationsinaqueryusingaggregatefunctionsandrecordgroupcalculations

– ChangethedisplayofdatabaseobjectsintheNavigationPane

NewPerspectivesonMicrosoftAccess2013 3

XPXPXPMaintainingandQueryingaDatabase

• Case- ChathamCommunityHealthServicesUpdatingandRetrieving InformationAboutPatients,Visits, andInvoices

– Userwantstomakesureshehasup- to-datecontactinformation

– Theofficestaffalsomustmonitorbillingactivitytoensurethatinvoicesarepaidontimeandinfull

– Developnewstrategiesforpromotingservicesprovidedbytheclinic

– Analyzeotheraspectsofthebusinessrelatedtopatientvisitsandfinances

NewPerspectivesonMicrosoftAccess2013 4

XPXPXPMaintainingandQueryingaDatabase(Cont.)

NewPerspectivesonMicrosoftAccess2013 5

XPXPXPMaintainingandQueryingaDatabase(Cont.)

NewPerspectivesonMicrosoftAccess2013 6

XPXPXPUpdatingaDatabase• Updating,ormaintaining,adatabaseistheprocessof

adding,modifying,anddeletingrecordsindatabasetablestokeepthemcurrentandaccurate

• ModifyingRecords– Tomakeminorchanges,orselect thefieldvaluetoreplace itentirely

• TheF2keyisatogglethatyouusetoswitchbetween navigationmodeandeditingmode

– Innavigation mode,Access selects anentire fieldvalue. Ifyoutypewhileyouareinnavigationmode,yourtypedentryreplaces thehighlighted fieldvalue

– Ineditingmode,youcaninsertordeletecharacters inafieldvaluebasedonthelocationoftheinsertion point

NewPerspectivesonMicrosoftAccess2013 7

XPXPXPUpdatingaDatabase(Cont.)

NewPerspectivesonMicrosoftAccess2013 8

XPXPXPUpdatingaDatabase(Cont.)• HidingandUnhidingFields– WhenyouareviewingatableorquerydatasheetinDatasheetview,youmightwanttotemporarilyremovecertainfieldsfromthedisplayeddatasheet,makingiteasiertofocusonthedatayou’reinterestedinviewing

– TheHideFieldscommandremovesthedisplayofoneormorefields• Canbeespeciallyusefulinatablewithmanyfields

– TheUnhideFieldscommandredisplaysanyhiddenfields

NewPerspectivesonMicrosoftAccess2013 9

XPXPXPUpdatingaDatabase(Cont.)• FindingDatainaTable– Accessprovidesoptionsyoucanusetolocatespecificfieldvaluesinatable• TheFindcommandsearchesatableorquerydatasheet,oraform,tolocateaspecificfieldvalueorpartofafieldvalue

NewPerspectivesonMicrosoftAccess2013 10

XPXPXPUpdatingaDatabase(Cont.)• DeletingRecords– Todeletearecord,youneedtoselecttherecordinDatasheetview,andthendeleteitusingtheDeletebuttonintheRecordsgroupontheHOMEtabortheDeleteRecordoptionontheshortcutmenu

NewPerspectivesonMicrosoftAccess2013 11

XPXPXPIntroductiontoQueries• Accessprovidespowerfulquerycapabilitiesthatallowyoutodothefollowing:– Displayselected fieldsandrecords fromatable– Sortrecords– Performcalculations– Generate datafor forms, reports,andotherqueries– Updatedatainthetables inadatabase– Findanddisplaydatafromtwoormore tables

• Theanswertoaselectqueryisreturnedintheformofadatasheet– Theresultofaqueryisalsoreferred toasarecordset because the

queryproducesasetofrecords thatanswersyourquestion

NewPerspectivesonMicrosoftAccess2013 12

XPXPXPIntroductiontoQueries(Cont.)

NewPerspectivesonMicrosoftAccess2013 13

XPXPXPCreatingandRunningaQuery

NewPerspectivesonMicrosoftAccess2013 14

XPXPXPCreatingandRunningaQuery(Cont.)

NewPerspectivesonMicrosoftAccess2013 15

XPXPXPUpdatingDataUsingaQuery

NewPerspectivesonMicrosoftAccess2013 16

• Aquerydatasheetistemporaryanditscontentsarebasedonthecriteriainthequerydesigngrid• Youcanstillupdatethedatainatableusingaquerydatasheet

• Insteadofmakingthechangesinthetabledatasheet,youcanmaketheminthePatientEmailquerydatasheetbecausethequeryisbasedonthePatienttable

• TheunderlyingPatienttablewillbeupdatedwiththechangesyoumake

XPXPXPCreatingaMultitableQuery

NewPerspectivesonMicrosoftAccess2013 17

• Amultitablequeryisaquerybasedonmorethanonetable

• Ifyouwanttocreateaquerythatretrievesdatafrommultipletables,thetablesmusthaveacommonfield

XPXPXP

• Sortingistheprocessofrearrangingrecordsinaspecifiedorderorsequence– Sometimesyoumightneed tosortdatabefore displayingorprintingit

tomeetaspecific request

• Tosortrecords,youmustselectthesortfield,whichisthefieldusedtodeterminetheorderofrecordsinthedatasheet

SortingDatainaQuery

NewPerspectivesonMicrosoftAccess2013 18

XPXPXPSortingDatainaQuery(Cont.)

• WhenworkinginDatasheetviewforatableorquery,eachcolumnheadinghasanarrowtotherightofthefieldname– ArrowgivesyouaccesstotheAutoFilter feature,whichenablesyoutoquicklysortanddisplayfieldvaluesinvariousways

NewPerspectivesonMicrosoftAccess2013 19

XPXPXPSortingDatainaQuery(Cont.)• SortingonMultipleFieldsinDesignView– Sortfieldscanbeuniqueornonunique

• Asortfield isunique ifthevalueinthesort fieldforeachrecord isdifferent

• Asortfield isnonunique ifmore thanonerecordcanhave thesamevalue forthesortfield– Whenthesortfieldisnonunique, recordswiththesamesortfieldvaluearegrouped together, buttheyarenotsorted inaspecificorderwithinthegroup

– Toarrange thesegroupedrecords inaspecificorder,youcanspecifyasecondary sort field,whichisasecond fieldthatdetermines theorderofrecords thatarealreadysortedbytheprimary sort field(the firstsortfieldspecified)

NewPerspectivesonMicrosoftAccess2013 20

XPXPXPSortingDatainaQuery(Cont.)

NewPerspectivesonMicrosoftAccess2013 21

XPXPXPFilteringData• Afilterisasetofrestrictionsyouplaceontherecordsto

temporarilyisolateasubsetoftherecords– Letsyouviewdifferent subsetsofdisplayedrecords sothatyoucan

focusononlythedatayouneed– Anapplied filter isnotavailable thenexttimeyourunthequeryor

opentheform(unless ithasbeensaved)

• ThesimplesttechniqueforfilteringrecordsisFilterBySelection– Letsyouselectallorpartofafieldvalue inadatasheet orform,and

thendisplayonlythoserecords thatcontaintheselected value inthefield

– Another technique forfiltering records istouseFilterByForm,whichchangesyourdatasheet todisplayblankfields

NewPerspectivesonMicrosoftAccess2013 22

XPXPXPFilteringData(Cont.)

NewPerspectivesonMicrosoftAccess2013 23

XPXPXPSelectionCriteriainQueries

NewPerspectivesonMicrosoftAccess2013 24

XPXPXP

• TotellAccesswhichrecordsyouwanttoselect,youmustspecifyaconditionaspartofthequery– Aconditionusuallyincludesoneofthecomparisonoperators

DefiningRecordSelectionCriteriaforQueries

NewPerspectivesonMicrosoftAccess2013 25

XPXPXP

• SpecifyinganExactMatch– Createaquerythatwilldisplayspecificrecords

• Thistypeofconditionisanexactmatchbecause thevalue inthespecified fieldmustmatchtheconditionexactlyinorder fortherecord tobeincludedinthequeryresults

DefiningRecordSelectionCriteriaforQueries(Cont.)

NewPerspectivesonMicrosoftAccess2013 26

XPXPXP

• ModifyingaQuery– Afteryoucreateaqueryandviewtheresults,youmightneedtomakechangestothequeryiftheresultsarenotwhatyouexpectedorrequire

DefiningRecordSelectionCriteriaforQueries(Cont.)

NewPerspectivesonMicrosoftAccess2013 27

XPXPXPDefiningRecordSelectionCriteriaforQueries(Cont.)

NewPerspectivesonMicrosoftAccess2013 28

XPXPXP

• UsingaComparisonOperatortoMatchaRangeofValues– Afteryoucreateandsaveaquery,youcandouble-clickthequerynameintheNavigationPanetorunthequeryagain

– ClicktheViewbuttontochangeitsdesign– Youcanalsouseanexistingqueryasthebasisforcreatinganotherquery

DefiningRecordSelectionCriteriaforQueries(Cont.)

NewPerspectivesonMicrosoftAccess2013 29

XPXPXPDefiningRecordSelectionCriteriaforQueries(Cont.)

NewPerspectivesonMicrosoftAccess2013 30

XPXPXPDefiningMultipleSelectionCriteriaforQueries

NewPerspectivesonMicrosoftAccess2013 31

• Multipleconditionsrequireyoutouselogicaloperatorstocombinetwoormoreconditions– NeedtousetheAndlogicaloperator

– IfyouplaceconditionsinseparatefieldsinthesameCriteriarowofthedesigngrid,allconditionsinthatrowmustbemetinorderforarecordtobeincludedinthequeryresults

– Ifyouplaceconditionsindifferent Criteriarows,arecordwillbeselectedifatleastoneoftheconditionsismet

– Ifnoneoftheconditionsaremet,norecordsareselected– WhenyouplaceconditionsindifferentCriteriarows,youareusingtheOrlogicaloperator

XPXPXPDefiningMultipleSelectionCriteriaforQueries(Cont.)

NewPerspectivesonMicrosoftAccess2013 32

XPXPXPDefiningMultipleSelectionCriteriaforQueries(Cont.)

NewPerspectivesonMicrosoftAccess2013 33

• TheAndLogicalOperator• Inthequerydesign,bothconditionsyouspecifywillappearinthesameCriteriarow;therefore,thequerywillselectrecordsonlyifbothconditionsaremet

XPXPXPDefiningMultipleSelectionCriteriaforQueries(Cont.)

NewPerspectivesonMicrosoftAccess2013 34

• TheOrLogicalOperator• Inthequerydesign,eitheroneoftwoconditionsissatisfiedorwhenbothconditionsaresatisfied

XPXPXPChangingaDatasheet’sAppearance

NewPerspectivesonMicrosoftAccess2013 35

• Youcanmakemanyformattingchangestoadatasheettoimproveitsappearanceorreadability– Fonttype,size,color,alignmentoftext,applydifferentcolorstotherowsandcolumns

• ModifyingtheFontSize– Dependingonthesizeofthemonitoryouareusingorthescreenresolution,youmightneedtoincreaseordecreasethesizeofthefonttoviewmoreorfewercolumnsofdata

XPXPXPChangingaDatasheet’sAppearance(Cont.)

NewPerspectivesonMicrosoftAccess2013 36

• ChangingtheAlternateRowColorinaDatasheet– Accessusesthemestoformattheobjectsinadatabase.Athemeisapredefinedsetofformatsincludingcolors,fonts,andothereffectsthatenhanceanobject’sappearanceandusability• TheOfficetheme,whichformatseveryotherrowinadatasheetwithagraybackgroundcolortodistinguishonerowfromanother,isthedefault

XPXPXPChangingaDatasheet’sAppearance(Cont.)

NewPerspectivesonMicrosoftAccess2013 37

XPXPXPCreatingaCalculatedField

NewPerspectivesonMicrosoftAccess2013 38

• Queriescanperformcalculations– Mustdefineanexpressioncontainingacombinationofdatabasefields,constants,andoperators

– Acalculatedfieldisafieldthatdisplaystheresultsofanexpressionbutitdoesnotexistinadatabase

– TheZoomboxisadialogboxthatyoucanusetoentertext,expressions,orothervalues

– ExpressionBuilderisanAccesstoolthatmakesiteasyforyoutocreateanexpression• Itcontainsaboxforentering theexpression, anoptionfordisplayingandchoosingcommonoperators, andoneormorelistsofexpression elements, suchastableandfieldnames

XPXPXPCreatingaCalculatedField(Cont.)

NewPerspectivesonMicrosoftAccess2013 39

XPXPXPCreatingaCalculatedField(Cont.)

NewPerspectivesonMicrosoftAccess2013 40

FormattingaCalculatedFieldYoucanspecifyaparticularformatforacalculated field, justasyoucanforanyfield,bymodifying itsproperties

XPXPXPUsingAggregateFunctions

NewPerspectivesonMicrosoftAccess2013 41

• Youcancalculatestatisticalinformation,suchastotalsandaverages,ontherecordsdisplayedinatabledatasheetorselectedbyaquery– UsetheAccessAggregatefunctionswhichperformarithmeticoperationsonselectedrecordsinadatabase

XPXPXPUsingAggregateFunctions(Cont.)

NewPerspectivesonMicrosoftAccess2013 42

• WorkingwithAggregateFunctionsUsingtheTotalRow– Toquicklyperformacalculationusinganaggregatefunctioninatableorquerydatasheet,youcanusetheTotalsbuttonintheRecordsgroupontheHOMEtab• Whenyouclickthisbutton,arowlabeled“Total”appearsatthebottomofthedatasheet

• Chooseoneoftheaggregatefunctions

XPXPXPUsingAggregateFunctions(Cont.)

NewPerspectivesonMicrosoftAccess2013 43

• CreatingQuerieswithAggregateFunctions– Aggregate functionsoperateontherecords thatmeetaquery’s

selectioncriteria– Youspecifyanaggregate function foraspecificfield,andthe

appropriate operation appliestothatfield’svalues fortheselectedrecords

XPXPXPUsingAggregateFunctions(Cont.)

NewPerspectivesonMicrosoftAccess2013 44

XPXPXPUsingAggregateFunctions(Cont.)

NewPerspectivesonMicrosoftAccess2013 45

• UsingRecordGroupCalculations– Inaddition tocalculatingstatistical informationonallorselected

records, youcancalculatestatistics forgroupsofrecords– TheGroup Byoperatordivides theselected records intogroupsbased

onthevalues inthespecified field• Those recordswiththesamevalue forthefieldaregroupedtogether, andthedatasheet displaysonerecord foreachgroup

• Aggregate functions,whichappear intheothercolumnsofthedesigngrid,providestatisticalinformationforeachgroup

XPXPXPWorkingwiththeNavigationPane

NewPerspectivesonMicrosoftAccess2013 46

• TheNavigationPaneisthemainareaforworkingwiththeobjectsina– Provides optionsforgroupingdatabase objectsinvariouswaystosuit

yourneeds– Dividesdatabaseobjects intocategories, andeachcategorycontains

groups– Thedefault category is

ObjectType,whicharrangesobjectsbytype—tables,queries, forms,andreports

– ThedefaultgroupisAllAccessObjects,whichappearsatthetopoftheNavigationPane

XPXPXPWorkingwiththeNavigationPane(Cont.)

NewPerspectivesonMicrosoftAccess2013 47

top related