Ms Access Guide

Embed Size (px)

Citation preview

  • 7/27/2019 Ms Access Guide

    1/59

    Lesson 1Introduction

    Basic concepts

    This tutorial is on Application Development with Microsoft Access.Let's define what we willbe doing:

    Application:a series of programs or computer codesthat execute tasks that a user wants

    done.

    Maintaining a list of your friends' addresses and phone numbers is a personal application.

    Producing the weekly payroll for 1 employees of a business is a commercial application.

    !unning a computer model to forecast tomorrow's weather is a scientific application.

    "e will look at commercialapplications only. "e'll lea#e the scientific stuff to the people

    at M.$.T.

    Development: design% create% make% build all the parts of the application.

    &nalye: talk to the client (the user) to find*out what he wants. $f you don't ha#e a userhandy% use your imagination and prior knowledge to guess what a user would want.

    +esign: create a modelof the system. & model is like a blueprintto a builder. $t is adrawing or a description of some kind of what the system will look like when finished.

    "hen you determine how things will work and how problems will be sol#ed. ,ou do thatbefore you start to write computer code.

    -reate: write the application using the software * &ccess% in this case. &nd while you're

    creating you're also testing and debugging to make sure that what you create works theway it's supposed to work.

    Microsoft Access:&ccess is part of Microsoft ffice

    . /owe#er% it is not included in the basic suite with "ord and 0xcel. ,ou need to get

    Microsoft Office Professional dition to ha#e &ccess.

    b#iously% if you intend to do this tutorial we ha#e to assume that you ha#e access to&ccess. $t really is impossible to do otherwise.

    "e are using &ccess . ,ou could do 2ust as well with &ccess 34. &ny application

    created in &ccess can be con#erted to the pre#ious #ersion of &ccess and anyapplication created in &ccess 34 can be used in &ccess . The sample applications are

    all in &ccess .

  • 7/27/2019 Ms Access Guide

    2/59

    Lesson ! for "aturda#$ April !%$ !&&'

    Desi(nin( the application

    )he *+ideo "tore*

    To illustrate how to use &ccess in a commercial applicationwe'll use a business that almost

    e#eryone is somewhat familiar with: the local #ideo rental store.

    Let's say that the store% Mi,e-s +ideo% is going to open for business in a few weeks and theowner% Mike% wants to ha#e a database application ready to go for opening day.

    ,ou% the Anal#st% will sit down with Mike and you will 5uestion him on what he wants to get from

    the computer application. Then you will draw the plans for the application% which we call themodel% and you will check with him again to make sure you ha#en't forgotten anything. nly

    then will you actually start to write the application in &ccess.

    Definin( the application

    "hy does Mike want a database in the first place6

    There are actually two main reasons.

    1. This is rather ob#ious: he is going to be renting thousands of mo#ies to thousands of

    customers. There has to be a system in place to track who has what mo#ie% when it wasrented% when it was returned% if it was late% if it was lost% who to call to get it back% etc.

    . To succeed in business you ha#e to anal#e your business: "ho are your customers *

    men6 women6 old6 young6 "hat are they renting6 "hat's selling and what isn't6 "hat doyou ha#e on the shel#es that is gathering dust6 "hat are they asking for6

    7o% a well/desi(neddatabase application will meet both those re5uirements. $t will do theroutine sales managementand% it will allow the user to do all the sales analysis he needs to do to

    make the business prosper.

    ,ou ha#e to keep both of those basic needs in mind when you work on the design.

    0ommercial reuirements desi(n

    This is the part where we identify what has to bedone to make the application perform all the

    commercial functions it has to ha#e.

    8irst% a word of warning: 7ince you're 2ustbeginning with this% we'll keep the exercice simple.

    "e know that there are many functions that you

    http://www.profsr.com/access/accless02.htmhttp://www.profsr.com/access/accless02.htm
  • 7/27/2019 Ms Access Guide

    3/59

    can do in the #ideo store: rent +9+s% rent 9/7

    mo#ies% rent games% buy pre#iously*#iewed mo#ies%buy popcorn% chips and cola% rent machines% etc.

    "e won't co#er all of those. "hich is what you

    should be doing when you do it for real: design the

    core applicationand get it working then% add

    other functions to it.ur core application is to track the rentals of

    mo#ies% +9+s and games. "e'll lea#e the popcorn

    and Pepsi for another session.

    The first thing you will disco#er is that there are entitiesthat you are working with. &n entit#is

    something you keep data on% an ob2ect that acts onother ob2ects.

    $n this application they are: 0ustomersand

    Movies. "e'll use the term Mo#ies to describe

    our products e#en if they are +9+s or games orwhate#er.

    ;ow% take out your pencil and paper and make alist of all the data% we call them fields% that you

    ha#e to keep for each entity. ,ou should getsomething like

    this:

  • 7/27/2019 Ms Access Guide

    4/59

    "hy do you need the customer's +. ,ou don't make a federal case out of it.

  • 7/27/2019 Ms Access Guide

    5/59

    or monthly sales and identify patterns. &s soon as something is starting to go off*track% themanager can take correcti#e action.

    This is 2ust the beginning in your career path to bigger and better databases.

    !ight now on the market there are databases containing many terab#tesof information (a

    terabyte B 1% gigs). There are applicationscalled Data warehousin(and Data minin(thatdig through those mountains of data looking for shopping trends% customer buying patterns% etc.

    This is going to be

  • 7/27/2019 Ms Access Guide

    6/59

    F. 2amin( convention: a standard format for field names in your application. 8or example%$ use the first letter of the table name as a prefix for field name: cGcust$+ for customer

    $+% cG8name for customer first name.

    The reason is that e#entually% when you get into many tables% you will run into duplicatefield names. $f you create a 7upplier table% the 7upplier may also ha#e a 8irst name. "hen

    you program the application it will be a lot easier if you can tell one from another at aglance: c34name will be -ustomerG8irstGname and s34name will be

    7upplierG8irstGname.

    /ere% all -ustomers fields start with c3and all Mo#ies fields start with m3.

  • 7/27/2019 Ms Access Guide

    7/59

    Lesson 5 for "aturda#$ April !%$ !&&'

    0reatin( the database

    8or more information and special deals

    related to any of the issues on thispage% place your cursor o#er the

    double*underlined links.&ll information supplied by

    >ontera.com.

    )he new *Mi,e+ideo* database

    To your keyboards. ")A6) A00""7

    +o you want to open an existing database or create a new one. $f this is your first session% you

    want to create a new database.

    &nd% because you want to learn something from the ground up% you won-t use the wiards$pages and pro2ects which are the database*creation templates.

    nce you'#e mastered the concept% then you can use the shortcuts and let &ccess guide you

    through the process.

    http://www.profsr.com/access/accless03.htmhttp://www.profsr.com/access/accless03.htm
  • 7/27/2019 Ms Access Guide

    8/59

    &nd again% to make it interesting% 2ust choose Ceneral +atabase.

  • 7/27/2019 Ms Access Guide

    9/59

    -hoose a name for the database and store it in a folder.

    $n &ccess% a database% no matter how many tables or forms or reports it contains% is stored in a

    single file. That file has the extension: .mdb(for Microsoft database). "hen you want to mo#e or

    copy or delete the database% all you ha#e to do is work with the one file.

    http://www.profsr.com/access/accless03.htmhttp://www.profsr.com/access/accless03.htm
  • 7/27/2019 Ms Access Guide

    10/59

    7o far% you ha#e an empty database.

    The first ob2ect you create to define the database is the table.

    & table is the description of an entity. $t is used to store the data. "hen you create the table you

    first describe its structure.

    & table in &ccess is sort of like a spreadsheet in 0xcel: it consists of rows and columns. nly% it is

    more organied than a spreadsheet and that organiation will later allow you to retrie#e the datain all kinds of ways.

  • 7/27/2019 Ms Access Guide

    11/59

    The desi(n view of the table is meant to define the structure.

    ,ou name all the columns (in technical 2argon they would be called attributes of the entit#).

    !emember to use the prefix for the table% in this case c3 because it's the 0ustomers table.

  • 7/27/2019 Ms Access Guide

    12/59

    Then% choose a Data )#pe for each column.

    The +ata Type defines what kind of data will be contained: text% numbers% H!L% dates% etc. Thislets the systemknow how much memory to reser#e and also% what you are allowed to do to the

    data. 8or example% if you specify that a column is a ;umber type% you won't be allowed to put

    I,J in it.

    To see the data types a#ailable% click on the +ata Type column and do 81 (the /elp function).

    /ere's what you should get:

    http://www.profsr.com/access/accless03.htmhttp://www.profsr.com/access/accless03.htm
  • 7/27/2019 Ms Access Guide

    13/59

  • 7/27/2019 Ms Access Guide

    14/59

    &nd here are the basic rules on how to use them:

    "hen you define a primar# ,e# fieldand it doesn't matter what the format is% use

    Auto2umber. $f the identifier is formatted% like &3*1EF% use )e8t.

    "hen the data is a dateof any kind% +ate of birth% +ate hired% $n#oice date% etc.% you

    ha#e to use the Date9)imedata type.

    Most fields will be )e8t. 0#en a phone number (it contains a dash)% or department number

    that happens to be 11.

    Hse 2umberonly for fields that will be used in calculations (K * ) like 5uantities or

    salaries. $f it does not ha#e to be calculated% use )e8t. 0#en if the +epartmentGnumber is

    11% define it as text: it's not the number one hundred and one% it's the characters

    11.

  • 7/27/2019 Ms Access Guide

    15/59

  • 7/27/2019 Ms Access Guide

    16/59

    8inally% repeat the whole process with the Movies tableand you will be well on your way.

  • 7/27/2019 Ms Access Guide

    17/59

    Lesson < for "aturda#$ April !%$ !&&'

    0reatin( relationships

    Identif#in( the tables

    &fter Lesson E% these are the tables you should ha#e.

    http://www.profsr.com/access/accless04.htmhttp://www.profsr.com/access/accless04.htm
  • 7/27/2019 Ms Access Guide

    18/59

    ;ote that there are se#eral fields in both tables that refer to Links to other table. The reason for

    that is that !elationships are #ery powerful in database design.

    Let's look at the case of credit cardsin the -ustomer table.

    $f you ha#e to keep a record of the customer's credit card name% number and expiry date you will

    create E fields in the table. b#iously% card number and date will be indi#idual but% you may ha#e% customers with 9isa. "hen you enter the customer's record you could 2ust type 9isa forthe card name.

  • 7/27/2019 Ms Access Guide

    19/59

    The solution to those problems is: don't key the card name into the record% select the name froma list% and the list will come from another table.

    $n this case% we create a -redit-ardtable and it will contain only a list of credit cards that we will

    accept.

    The customer record won't actually contain the credit card name% it will contain a pointer to the-redit-ard table. $f e#er a card company changes its name% we only need to change the name in

    the -redit-ard table and all customers who point to that name will automatically be changed.

    Relationships and data types

    One crucial point you have to keep in mind when describing

    relationships: the link is alwaysfrom the primary key of onetable to a field in another table. The primary key can be any

    type field - in CreditCards it's a Text!"# field. The other endof the relationship must contain a field of the same type and

    size. $o% in the Customers table% c&Cardame must also be a

    Text!"# field.

    (n the other tables we'll look at in a minute% the primary key isdefined as an )utoumber field. )utoumber is not a type%

    it's a function. The data type is Numberand the Length is

    Long integer. (n those relationships the other end of the linkmust also be defined as a umber field.

    (n all relationships involving an )utoumber% the other fieldmust be a Number. (n the *anguage table l&o is

    )utoumber so% m&*anguage in +ovies is umber *ong

    integer.

    ) common mistake is to try to link two )utoumber fields

    together.

    The -redit-ard table doesn't ha#e to be complicated% as you can see:

    http://www.profsr.com/access/accless04.htmhttp://www.profsr.com/access/accless04.htm
  • 7/27/2019 Ms Access Guide

    20/59

    To create the !elationship% hit the !elationships button on the toolbar:

  • 7/27/2019 Ms Access Guide

    21/59

    Referential integrity:

    this is important, it

    means that you can'tenter a credit card that

    is not in theCreditCard table, this

    keeps the data honest,

    you almost alwayswant to do this.

    Cascade update:if acard name changes% all

    customer records will

    be updatedautomatically toreflect the change,

    that's O - usually

    you want this tohappen.

    Cascade delete:ifyou delete a credit

    card name from the

    CreditCard table% all

    customer recordsholding that card will

    be deleted, you don't

    want that to happen,don't check this box.

  • 7/27/2019 Ms Access Guide

    22/59

    ;ow% apply the same idea to the Mo#ies table.

    The fields: -ategory% !ating% Language% 8ormat can all be stored in other tables and linked to

    Mo#ies.

    The same principles will apply. $f you add a new category% you add it only once to the -ategories

    table. $f a category name changes% you change it once% in the -ategories table.

    The only difference in those tables is that we'#e gi#en each item in the list a number: 1 B &ction%

    B !omance% etc. The list will still work the same as the -redit-ard table.

    8or example% the Language table:

  • 7/27/2019 Ms Access Guide

    23/59

    /ere's what you will e#entually get when all the tables and relationships are set*up. +on't worry

    about all the extra tables% we'll get to those in the following lessons.

    2e8t wee,: nterin( data into tables. "ee #ou then7

  • 7/27/2019 Ms Access Guide

    24/59

    Lesson % for "aturda#$ April !%$ !&&'

    nterin( data

    ;or,in( with the data (rid

    "hen you ha#e a large 5uantity of data to input% the data grid is not a bad way to go.

    ,ou normally won't use this techni5ue for day*to*day operations* we will create forms for that *

    but it is useful at startup.

    ,ou will ha#e to modify some of the properties of the fields in the table to make the best use ofall the functions. $t is recommended to test the changes on a few entries at first.

    ,ou get the data grid when you click Openon a Table in the +atabasewindow.

    The data grid acts like a spreadsheet. 8or people used to working with 0xcelit should look 5uitefamiliar. 0#en the tools used to manipulate the data are similar to those used for the

    spreadsheet.

    nsurin( the accurac# of data

    http://www.profsr.com/access/accless05.htmhttp://www.profsr.com/access/accless05.htm
  • 7/27/2019 Ms Access Guide

    25/59

    Default valuesand 9alidation are #ery important. They ensure that the information that getsinto the database is as exact as possible.

    $f there is a field where you see you will enter the same data more than ?@ of the time% use a

    +efault. $t will display automatically and you only ha#e to tab o#er it to accept it. $f you ha#e tochange it% you 2ust enter a new #alue o#er the default.

    & +alidation ruleis a check on the accuracy of the input. 7ex can only be M or 8% for

    example. $f a field had to be less tha 1 you would code the #alidation rule as: N 1.

    $f the operator makes a mistake on a #alidated field and there is no +alidation te8t% chances arethe systemwill display a weird error message (,ou commited a fatal error= ,ou will die= can be

    somewhat intimidating.) The #alidation text is your way of telling the operator what he shouldha#e done.

  • 7/27/2019 Ms Access Guide

    26/59

  • 7/27/2019 Ms Access Guide

    27/59

    -hoosing the input from a list is a lot more exact than keying it.

    The table containing the list should already ha#e been created. Oust select the table.

  • 7/27/2019 Ms Access Guide

    28/59

  • 7/27/2019 Ms Access Guide

    29/59

    $f the table for the list contains more than one column (Language% for example)% 0olumn countwill be and Bound columnwill be 1.

  • 7/27/2019 Ms Access Guide

    30/59

  • 7/27/2019 Ms Access Guide

    31/59

    Lesson = for "aturda#$ April !%$ !&&'

    0reatin( a data entr# 4orm

    ;or,in( with the Auto4orm ;iard

    $n the pre#ious lesson we used the data grid to get information into the tables. &lthough useful insome situations% it is not #ery practical for day*to*day operationsbecause it is not a format that

    non*programming types are comfortable with.

    0#erybody is familiar with forms. 7o% to display information from the tables or to input data intothe tables we'll create a form for e#ery table in the database.

    "e'll do the -ustomers form first and then% all the other tables can be done the same way.

    There are se#eral ways to create forms. $t is possible to do it from scrtach but that is rarelynecessary.

    The easiest is to use the "iard to get the basic design and then customie it.

    http://www.profsr.com/access/accless06.htmhttp://www.profsr.com/access/accless06.htm
  • 7/27/2019 Ms Access Guide

    32/59

  • 7/27/2019 Ms Access Guide

    33/59

    &s soon as $ ha#e the form created% before $ go further% $ will "aveand 2amethe form. There isno problem in gi#ing the form the same name as the table * in fact it is usually easier to associate

    the two ob2ects when they ha#e the same name. &ccess keeps all the ob2ects separate so in factthere will not be a conflict if $ ha#e a 0ustomers tableand a corresponding 0ustomers form.

    ;ow $ can customie the form.

  • 7/27/2019 Ms Access Guide

    34/59

    &ll the ob2ects on the form% the boxes% lists% titles are called controls.

    -ontrols can be changed% mo#ed around% resied% colored% etc. ,ou can select se#eral controls atonce using the standard "indowsmethods: shift*click% control*click and change all the ones that

    are selected using the 0dit toolbar.

    $f you ha#e to go to the properties of the controls% you open the Properties windowwith a!ight*click on the control.

    http://www.profsr.com/access/accless06.htmhttp://www.profsr.com/access/accless06.htmhttp://www.profsr.com/access/accless06.htmhttp://www.profsr.com/access/accless06.htm
  • 7/27/2019 Ms Access Guide

    35/59

    &s you do the changes% take a look at the results fre5uently and ad2ust the form accordingly.

    0#ery time you go to 8orm mode% do a "aveat the same time.

  • 7/27/2019 Ms Access Guide

    36/59

  • 7/27/2019 Ms Access Guide

    37/59

    nce the layout is complete there is one last% #ery important task to do.

    $t is called the )ab order. $t is the order in which the cursor mo#es when you hit the NTab key

    on the keyboard.

    "hen the form is first created% the Tab order will follow the order of the controls on the form.

  • 7/27/2019 Ms Access Guide

    38/59

    $t is ver# importantto make sure that the Tab order follows the order of the controls.

  • 7/27/2019 Ms Access Guide

    39/59

  • 7/27/2019 Ms Access Guide

    40/59

    To do other operations on the form% use the appropriate button in the toolbar.

    ,ou can delete an existing customer or add a new one.

  • 7/27/2019 Ms Access Guide

    41/59

    $n the case where you ha#e ?% customers and you ha#e to find the record for a particular one%

    do a 4indoperation using the toolbar.

  • 7/27/2019 Ms Access Guide

    42/59

    ;ow% create a form for the Moviestable using the same techni5ue.

  • 7/27/2019 Ms Access Guide

    43/59

    Lesson > for "aturda#$ April !%$ !&&'

    0reatin( simple ?ueries

    8or more information and special deals

    related to any of the issues on thispage% place your cursor o#er the

    double*underlined links.&ll information supplied by

    >ontera.com.

    4indin( answers to uestions

    ;ow% let's say we'#e created the Mo#ies table and% using the appropriate 8orm% we'#e input the

    mo#ies that we carry.

    /opefully we ha#e thousands of entries in that table to gi#e our customers the greatest choicepossible.

    &nd% if you look at the example below you will note that we usually ha#e se#eral copies of each

    mo#ie in stock. 0ach 9/7 tape or +9+ carries a different item number but the rest of the

    information has simply been copied and pasted from one to the other.

    http://www.profsr.com/access/accless07.htmhttp://www.profsr.com/access/accless07.htm
  • 7/27/2019 Ms Access Guide

    44/59

    "e'll use the Mo#ies table to look at ?ueries.

    & 5uery is a 5uestion% a search% an interrogation. $n &ccess it is an ob2ect of the database. &

    5uery is a stored 5uestion. ;ot the answer% mind you% @ust the uestion.

    $f a customer comes in and wants to know what we ha#e starring Tom -ruiseor directed by7pielbergor released in 133?% all those are 5ueries. &s long as the information is stored in the

    database we can get it.

    "e will also ha#e 5ueries that are repeated all the time and we will ha#e to take care of thosealso:

    "hat were the sales figures for last month% for last year6/ow many customers do we ha#e and what is their a#erage age6 &re there more men or

    women6

    The simplest 5uery would return a list of a whole table.

  • 7/27/2019 Ms Access Guide

    45/59

  • 7/27/2019 Ms Access Guide

    46/59

    The example abo#e brings up an interesting problem * if $ ha#e ? copies of a mo#ie by a

    director% whene#er $ use a 5uery on director% or star% or title for that matter% the same mo#ie willcome up ? times. "hat $ actually meant was: show me all the uniuemo#ies by a director% not

    the tapes or +9+'s.

    There is a simple way to correct that and that's to use the Properties of the Query% as shown

    below:

  • 7/27/2019 Ms Access Guide

    47/59

    $ can now sa#e the Query so that if the 5uestion e#er comes up again $ only ha#e to go to theQuery ob2ects and open the 5uery that $ had sa#ed.

    $'ll gi#e it a name that will remind me of what it does% not 2ust Query1.

    Oust to remind you again: the 5uery results are not sa#ed here. nly the structureof the 5uery

    is sa#ed. $f we add a bunch of new mo#ies before we run the 5uery again% all those mo#ies% ifthey apply% will show up next time.

  • 7/27/2019 Ms Access Guide

    48/59

    "pecif#in( criteria

    ,ou may ha#e noticed in all the pics abo#e that the title bar always refers to *"elect ?uer#*.

    That means that we are selecting something. $n fact% we usually select somerecordsfrom thetable. "e rarely ha#e to see all the mo#ies% or all the customers.

    To select some records we will use the 0riteria linein the 5uery to specify a condition for arecord to be included in the result.

    8or example: 7how me all Tom -ruise mo#ies in stock. 2ote:in all these $ will use the Hni5ue9alues property so that $ don't get F or ? repetitions of the same mo#ie.

    http://www.profsr.com/access/accless07.htmhttp://www.profsr.com/access/accless07.htm
  • 7/27/2019 Ms Access Guide

    49/59

    To define criteria we use comparison operators. These are the signs most people are familiar

    with from programming% and there are a few new ones.

    = eual

    > greater than

    = greater or eual

  • 7/27/2019 Ms Access Guide

    50/59

    < > not eual

    not reverse condition

    lie

    between

    8amples:

    &ll mo#ies with a #alue of R? or more.mG-ost B ?

    &ll mo#ies produced before 133.

    mG,earProduced N 133

    &ll mo#ies released after 133?.mG9ideo!elease S133?*1*E1S

    &ccess is #ery flexible. /owe#er you should get into the habit of using punctuation correctly.Hsually% text fields% or strings% are enclosed in 5uotes: Tom -ruise% dates are enclosed in

    number signs: S*1*1S and numbers are enclosed in nothing.

    The betweenoperator is used like it's pronounced:

    mG,earProduced between 13A and 134it is inclusi#e in that 13A and 134 both appear in the result

    The li,eoperator is #ery useful and is used extensi#ely when working with text fields.

    $t is used in combination with the % the wildcard character.

    7how all stars with a name beginning with Tom.m3"tar li,e *)om*

    stands for any string% so that the 5uestion becomes Tom followed by something

    7how all mo#ie titlescontaining the word wind.

    m3)itle li,e *wind*mGTitle is any string% wind% any stringf course this will return Cone with the "ind along with any title containing window or

    winding% etc.

    7how all mo#ies starring somebody not named Tom.

    m3"tar not li,e *tom*

    $f there are criteria in columns% both ha#e to be true. This is an A2Dcondition.

    "hat mo#ies ha#e 7pielberg and Tom /anks done together6

    http://www.profsr.com/access/accless07.htmhttp://www.profsr.com/access/accless07.htm
  • 7/27/2019 Ms Access Guide

    51/59

    To get an ! condition% use the ! line after criteria.

    7how mo#ies starring 9i#ien Leighor Tom -ruise.

    http://www.profsr.com/access/accless07.htmhttp://www.profsr.com/access/accless07.htm
  • 7/27/2019 Ms Access Guide

    52/59

  • 7/27/2019 Ms Access Guide

    53/59

    Lesson for "aturda#$ April !%$ !&&'

    More comple8 ?ueries

    8or more information and special dealsrelated to any of the issues on this

    page% place your cursor o#er thedouble*underlined links.

    &ll information supplied by>ontera.com.

    ;or,in( with dates

    "hene#er you de#elop a commercial application% there is absolutely no way that you can get by

    without using date fields. The 9ideo application has Mo#ie !ental date% !eturn date% +ate*of*birth%

    !eport dates. The +ating 7er#ice has dates for dates. The -redit card has an 0xpiry date. Thereare

  • 7/27/2019 Ms Access Guide

    54/59

    $n &ccess% a date or time constant should be identified with S ... S% as in:... Cm3videorelease E F!&&1/&1/&1FG

    To begin with% know that you can do some calculations with dates as you do with numbers.

    F!&&5/&1/51F / F!&&5/&1/&1F will return 5&% the number of days between the dates.

    F!&&5/&1/&1F H 5will return F!&&1/&1/&

  • 7/27/2019 Ms Access Guide

    55/59

    person has had his birthday yet this year or not. Hsually it doesn'y work #ery well.

    To calculate the exact age% the following formula is 5uite accurate. There may be a small #ariation

    of a day or so once in a while.

    I2)KDatediffK-d-$ c3BirthDate$ nowK95=%.!%

    -alculate the number of days between birth and now and di#ide by the exact number of days in a

    year% which% as you know% is EA?.? and not EA?. That takes leap years into account.

    The $nteger function% I2)K % truncates the result so that ?.3 becomes ?% for exampleD theperson is ? years old until the day she turns AD after the age of ?% you rarely hear people say

    that they are ? and a half years old.

    ?ueries that calculate

    $n the pre#ious lesson we created se#eral 5ueries to get information from a table.

  • 7/27/2019 Ms Access Guide

    56/59

    &s you can see% to put calculations into a 5uery:

    Pick an empty column

    +efine a heading * a name followed by a colon * for example% &ge:

    "hen you use a column name in the calculation% it must be enclosed in s5uare brackets as%

    cG+

  • 7/27/2019 Ms Access Guide

    57/59

    pdate and Delete ueries

    3@ of the time when you use a 5uery it will be a 7elect 5uery * one that displays information.

    nce in a while you will ha#e to do maintenance operationson the tables: change a group ofprices% delete all obsolete items% etc. 8or those operations you use a different type of 5uery

    called: an action uer#.

    "e'll look at two: the Hpdate and the +elete.

    8irst% create a new 5uery and specify the table that will be affected% same as the 7elect 5uery.

    Then% choose the Query type from the toolbar.

    http://www.profsr.com/access/accless08.htmhttp://www.profsr.com/access/accless08.htm
  • 7/27/2019 Ms Access Guide

    58/59

    8or the Hpdate 5uery% specify the operation on the update line: what you want to change and the

    criteria: which records will be changed.

  • 7/27/2019 Ms Access Guide

    59/59

    8or the +elete 5uery% all you ha#e to specify is the -riteria.

    ,ou cannot ask to delete certain columns in certain recordsD you can only delete entire records.

    &fter choosing +elete 5uery% specify the -riteria to delete records: