1 Access Notes
1 Access Notes
A database is a collection of information that's related to a particular subject or purpose, such as tracking customer
orders or maintaining a music collection. Microsoft Access, is one such program, however the field of database
programs is full of other rival programs that compete successfully these include Paradox, dBase, FoxPro, Sybase,
Oracle, Lotus Approach, FoxBASE+ etc. If your database isn't stored on a computer, or only parts of it are, you may be
tracking information from a variety of sources that you have to coordinate and organize yourself.
Unlike other database programs, when using Microsoft Access, you can manage all your information from a single
database file. Within this file, You divide your data into separate storage containers called tables; view, add, and
update table data by using forms; find and retrieve just the data you want by using queries; and analyze or
print data in a specific layout by using reports. You can also allow users to view, update, or analyze the
database's data from the Internet or an intranet by creating data access pages.
STEP ONE
Step 1. Determine The Purpose Of Your Database
The first step in designing a database is to determine its purpose and how it's to be used. You need to know what
information you want from the database. From that, you can determine what subjects you need to store facts about
(the tables) and what facts you need to store about each subject (the fields in the tables). This may be achieved using
the following fact finding techniques:
(a.)Conducting Interviews with the would be users of the database
(b.) Through Observation
(c.) Through Questionnaires
(d.) Through Document Review
STEP TWO
Step 2. Determine The Tables You Need
Determining the tables can be the trickiest step in the database design process. That's because the results you want
from your database — the reports you want to print, the forms you want to use, the questions you want answered —
don't necessarily provide clues about the structure of the tables that produce them. You don't need to immediately
start designing your tables using Microsoft Access. In fact, it may be better to sketch out and rework your design on
paper first.
STEP THREE
Step 3. Determine the fields you need
Each table contains information about the same subject, and each field in a table contains individual facts about
the table's subject. For example, a customer table may include company name, address, city, state, and phone
number fields. (Fields – Refer to an element of a table that contains a specific item of information, such as a last
name. When sketching out the fields for each table, the following tips should be borne in mind:
Relate each field directly to the subject of the and names of fields (columns), controls, and
table. properties that evaluates to a single value.
Don't include derived or calculated data (data that Include all the information you need.
is the result of an expression – i.e. any combination
Store information in its smallest logical parts (for
of operators, constants, literal values, functions,
example, Surname, First Name and Last Name,
rather than Name).
The following table summarizes all the field data types available in Microsoft Access, their uses, and their storage
sizes. Data For example, in a Microsoft Access database, Number data type fields store numerical data that will be
used in mathematical calculations. Use the Currency data type to display or calculate currency values.
DATA
USED FOR
TYPE
Text Text or combinations of text and numbers, such as addresses. Also numbers that do not require
calculations, such as phone numbers, part numbers, or postal codes. Up to 255 characters.
Memo
Lengthy text and numbers, such as notes or descriptions. Up to 64,000 characters.
Number Numeric data to be used for mathematical calculations, except calculations involving money (use
Currency type). The FieldSize property can be used to define the specific Number type.
Date/Time
Dates and times.
Currency Currency values. Use the Currency data type to prevent rounding off during calculations. Accurate to
15 digits to the left of the decimal point and 4 digits to the right.
AutoNumbe
r Unique sequential (incrementing by 1) or random numbers automatically inserted when a record is
added.
Yes/No
Fields that will contain only one of two values, such as Yes/No, True/False, On/Off.
OLE Object Objects (such as Microsoft Word documents, Microsoft Excel spreadsheets, pictures, sounds, or other
binary data), created in other programs using the OLE protocol that can be linked to or embedded in
a Microsoft Access table.
Colored and underlined text or a graphic that you click to jump to a file, a location in a file, an HTML
Hyperlink page on the World Wide Web, a HTML page on an intranet, Gopher, Telnet, newsgroup, or an FTP
sites.)
Lookup Creates a field that allows you to choose a value from another table or from a list of values using a
Wizard combo box. Choosing this option in the data type list starts a wizard to define this for you. The same
size as the primary key field that is also the Lookup field
Note Number, Date/Time, Currency, and Yes/No data types provide predefined display formats. Set the Format
property to choose from the formats available for each data type. You can also create a custom display format for all
data types except the OLE Object data type.
STEP FOUR
Step 5. Identify The Field Or Fields With Unique Values In Each Record
In order for Microsoft Access to connect information stored in separate tables — for example, to connect a customer
with all the customer's orders — each table in your database must include a field or set of fields that uniquely
identifies each individual record in the table. Such a field or set of fields is called a primary key or a key field.
1. A primary key cannot allow Null values;
2. Must always have a unique index i.e. cannot contain duplicate values and;
3. It is used to relate a table to foreign keys in other tables.
STEP FIVE
Step 6. Creating The Database and Other Objects
DATABASE OBJECTS
Tables
This is the fundamental structure of a relational database management system. In Microsoft Access, a table is an object that stores
data in records. The data is usually about a particular category of things, such as employees or orders.
Store data once in one table, but view it from multiple different locations. When you update the data or make changes, it is
automatically updated everywhere it appears. To store your data, create one table for each type of information that you track.
Query
Is a question about the data stored in your tables, or a request to perform an action on the data. To find and retrieve just the data
that meets conditions that you specify, including data from multiple tables, create a query. A query can also update or delete
multiple records at the same time, and perform predefined or custom calculations on your data.
Form
Is a Microsoft Access database object on which you place controls for taking actions or for entering, displaying, and editing data in
fields. To easily view, enter, and change data directly in a table, create a form.
Report
Refers to a Microsoft Access database object that prints information formatted and organized according to your specifications.
Examples of reports are sales summaries, phone lists, and mailing labels. To analyze your data or present it a certain way in print,
create a report. For example, you might print one report that groups data and calculates totals, and another report with different
data formatted for printing mailing labels.
A Web page that has a connection to a database; in a data access page, you can view, add to, edit, and manipulate the data stored
in the database. To make data available on the Internet or an intranet for interactive reporting, data entry, or data analysis, use a
data access page. Microsoft Access retrieves the data from one or more tables and displays it on the screen with the layout you
choose in the Page Wizard, or a layout that you create from scratch.
Macro
Module
Object 1. Tables:
A table is a collection of data about a specific topic, such as products or suppliers. Ideally they are data structures.
Containing information in columnar manner. Using a separate table for each topic means that you store that data only
once, which makes your database more efficient, and reduces data-entry errors. Tables organize data into columns
(called fields) and rows (called records). A common field relates two tables so that Microsoft Access can bring together
the data from the two tables for viewing, editing, or printing. This key is known as a Primary key in one of the tables,
while on the table where it is used to establish the link, it is called the Foreign Key. In table Design view, you can
create an entire table from scratch, or add, delete, or customize the fields in an existing table. In table Datasheet
view, you can add, edit, view, or otherwise work with the data in a table.
Creating a table
Microsoft Access provides two ways to create a table. You can create a blank (empty) table for entering your own
data, or you can create a table using existing data from another source (Through Wizards).
A. Create a Table from scratch in Design view
1. If you haven't already done so, switch to the Database window. You can press F11 to switch to the Database
window from any other window.
2. Click Tables under Objects, and then click New on the Database window toolbar.
3. Double-click Design View.
4. Define each of the fields in your table.
5. Define a primary key field before saving your table (primary key - One or more fields (columns) whose value or
values uniquely identify each record in a table. A primary key cannot allow Null values and must always have
a unique index. A primary key is used to relate a table to foreign keys in other tables.
Note
You don't have to define a primary key, but it's usually a good idea. If you don't define a primary key, Microsoft
Access asks if you want it to create one for you when you save the table. When you are ready to save your table,
click Save on the toolbar, and then type a name for the table
You can use the Format property to customize the way numbers, dates, times, and text are displayed and printed.
For example, if you've created a field called Price, you can set its Format property to Currency and its
DecimalPlaces property to 2 or Auto. So that if you enter a value like 4321.678, the number would be displayed as
$4,321.68. You can use one of the predefined formats or you can create a custom format by using formatting symbols.
Use the Memo data type if you need to store more than 255 characters. A Memo field can store up to 64,000
characters. If you want to store formatted text or long documents, you should create an OLE field instead of a Memo
field. Both Text and Memo data types store only the characters entered in a field; space characters for unused
positions in the field aren't stored.
SYMBO DESCRIPTION If you are creating a Number field, in the bottom part of the window set
L the FieldSize property to the size you want. To set a display format for
your field, in the bottom part of the window click in the Format box,
< Force all characters to lowercase. click the arrow, and select the format you want.
> Force all characters to uppercase.
When Should I create a field for Numbers or Currency?
SETTING DESCRIPTION
Currency Use the thousand separator; follow the settings specified in Regional Settings in
Windows Control Panel for negative amounts, decimal and currency symbols, and
decimal places.
Euro Use the currency format, with the euro symbol, regardless of the currency symbol
specified in Regional Settings in Windows Control Panel.
Fixed Display at least one digit; follow the settings specified in Regional Settings in Windows
Control Panel for negative amounts, decimal and currency symbols, and decimal
places.
Standard Use the thousand separator; follow the settings specified in Regional Settings in
Windows Control Panel for negative amounts, decimal symbols, and decimal places.
Percent Multiply the value by 100 and append a percent sign (%); follow the settings specified
in Regional Settings in Windows Control Panel for negative amounts, decimal symbols,
and decimal places.
Storing dates and times in a Date/Time field ensures that dates and times will be sorted properly. Also, changes made
to the date or time formats that are specified through Regional Settings, Windows Control Panel. You can set the
Format property to predefined date and time formats or use custom formats for the Date/Time data type.
The following table shows the predefined Format property settings for the Date/Time data type.
SETTING DESCRIPTION
General Date
(Default) If the value is a date only, no time is displayed; if the value is a time only, no date is
displayed. This setting is a combination of the Short Date and Long Time settings. Examples:
4/3/93, 05:34:00 PM, and 4/3/93 05:34:00 PM.
Long Date
Same as the Long Date setting in the Regional Settings Properties dialog box in Windows
Control Panel. Example: Saturday, April 3, 1993.
Short Date
Same as the Short Date setting in the Regional Settings Properties dialog box in Windows
Control Panel. Example: 4/3/93. Warning The Short Date setting assumes that dates
between 1/1/00 and 12/31/29 are twenty-first century dates (that is, the years are assumed
to be 2000 to 2029). Dates between 1/1/30 and 12/31/99 are assumed to be twentieth
century dates (that is, the years are assumed to be 1930 to 1999).
Long Time
Same as the setting on the Time tab in the Regional Settings Properties dialog box in
Windows Control Panel. Example: 5:34:23 PM.
AutoNumbers that increment by one are the most common kind of AutoNumber and are a good choice for use
as a table's primary key.
Random AutoNumbers will generate a random number that is unique to each record within the table.
If you specify one predefined format and then enter an equivalent value, the predefined format of equivalent value will
be displayed. For example, if you enter True or On in a text box control with its Format property set to Yes/No, the
value is automatically converted to Yes.
Example showing a custom yes/no format for a text box control.
The control displays the word "Always" in blue text for Yes, True, or On, and the word "Never" in red text for No,
False, or Off.
;"Always"[Blue];"Never"[Red]
Creating a field to store OLE objects (Pictures, Word Documents etc)
In the Data Type column, click the arrow and select OLE Object.
Note OLE Object fields are used to store data such as Microsoft Word or Microsoft Excel documents, pictures, sound,
and other types of binary data created in other programs. OLE objects can be linked to or embedded in a field in a
Microsoft Access table.
When you click the Finish button, Microsoft Access creates the Lookup field and sets certain field properties based on
the choices you made in the wizard. The combo box or list box is created automatically for the form.
Note You can also enter the input mask definition in the property sheet without using the wizard. In most cases, it's
easiest to use the wizard, but for Number and Currency fields, you must enter the input mask definition manually.
An input mask is used in fields (in tables and queries) and in text boxes and combo boxes (in forms) to format data
and provide some control over what values can be entered. An input mask consists of literal characters (such as
spaces, dots, dashes, and parentheses) that separate blanks to fill in. Input masks are primarily used in Text and
Date/Time fields, but can also be used in Number or Currency fields.
Prepared by Fred @2024
Page 9
CHARACTER DESCRIPTION
! Causes the input mask to display from right to left, rather than from left to right.
Characters typed into the mask always fill it from left to right.
\ Causes the character that follows to be displayed as a literal character. Used to display
any of the characters listed in this table as literal characters (for example, \A is
displayed as just A).
Password Password creates a password entry text box. Any character typed in the text box is
stored as the character but is displayed as an asterisk (*).
Default Value…
You can use the Default Value property of a field to specify a value that is automatically entered into that field when
you add a new record
Quantity 1 1
Region "MT" MT
Region "New York, N.Y." New York, N.Y (note that you must enclose the value in
quotes if it includes punctuation)
Validation Rules…
Validation rule - A rule that sets limits or conditions on what can be entered in one or more fields. You
can set validation rules for a field, a record, or a control on a form. A validation rule for a field or
control is checked when you move to a different field or control. A validation rule for a record is
checked when you move to a different record. Microsoft Access displays the message specified in the
Validation Text property whenever the rule is violated.
Like "K???" Value must be four characters beginning with the letter K.
Object 2. FORMS
ShipCity "London" Or "Hedge End" Uses the Or operator to display orders shipped to London or Hedge
End.
ShippedDate Between #1/5/95# And Uses the Between...And operator to display orders shipped no earlier
#1/10/95# than 5-Jan-95 and no later than 10-Jan-95.
ShipCountry In("Canada", "UK") Uses the In operator to display orders shipped to Canada or the UK.
ShipCountry Not "USA" Uses the Not operator to display orders shipped to countries other
than the USA.
ShipName Like "S*" Orders shipped to customers whose name starts with the letter S.
Examples of expressions that calculate or manipulate dates, and then use the result as criteria
Field Expression Description
RequiredDate Between Date( ) And DateAdd("m", 3, Uses the Between...And operator and the DateAdd and Date
Date( )) functions to display orders required between today's date and
three months from today's date.
OrderDate < Date( )- 30 Uses the Date function to display orders more than 30 days old.
OrderDate Year([OrderDate])=1996 Uses the Year function to display orders with order dates in 1996.
OrderDate DatePart("q", [OrderDate])=4 Uses the DatePart function to display orders for the fourth
calendar quarter.
ShipName Like "S*" Orders shipped to customers whose names start with the letter S.
ShipName Like "*Imports" Orders shipped to customers whose names end with the word "Imports".
ShipName Like "[A-D]*" Orders shipped to customers whose names start with A through D.
ShipName Like "*ar*" Orders shipped to customers whose names include the letter sequence "ar".
There are many types of calculations you can perform in a query. For example, you can calculate the sum or average
of the values in one field, multiply the values in two fields, or calculate the date three months from the current date.
When you display the results of a calculation in a field, the results aren't actually stored in the underlying table.
Therefore, you can't manually update the calculated results. To display the results of a calculation in a field, you can
use a predefined calculation that Microsoft Access provides or custom calculations you define.
A custom calculation enables you to perform numeric, date, and text calculations on each record using data from one
or more fields. For example, with a custom calculation, you can multiply one field's values by a set amount, find the
difference between two dates stored in separate fields, combine several values in a Text field, or create subqueries.
For custom calculations, you need to create a new calculated field.
EXPRESSION DESCRIPTION
FullName: [FirstName] & " " & [LastName] Displays the value of the FirstName and LastName fields, separated by a
space, in the FullName field.
Address2: [City] & " " & [Region] & " " & Displays the value of the City, Region, and PostalCode fields, separated by
[PostalCode] spaces, in the Address2 field.
EXPRESSION DESCRIPTION
PrimeFreight: [Freight] * 1.1 Displays freight charges plus 10 percent in the PrimeFreight field.
OrderAmount: [Quantity] * [UnitPrice] Displays the product of the values in the Quantity and UnitPrice fields in the
OrderAmount field.
LeadTime: [RequiredDate] - Displays the difference between the values in the RequiredDate and ShippedDate
[ShippedDate] fields in the LeadTime field.
TotalStock: [UnitsInStock]+ Displays the sum of the values in the UnitsInStock and UnitsOnOrder fields in the
[UnitsOnOrder] TotalStock field.
EXPRESSION DESCRIPTION
LagTime: DateDiff("d", [OrderDate], Uses the DateDiff function to display in the LagTime field the number of days
[ShippedDate]) between the order date and ship date.
YearHired: DatePart("yyyy",[HireDate]) Uses the DatePart function to display in the YearHired field the year each
employee was hired.
Age: Year(Date())-Year([BirthDate]) Returns the employees age in years by subtracting the birthdate from
today’s date indicated in years.
Date( )- 30 Uses the Date function to display the date 30 days prior to the current date.
The wizard asks you detailed questions about the record sources, fields, layout, and format you want and creates a
report based on your answers.