Professional Documents
Culture Documents
Q An Overview of Database Management System E
Q An Overview of Database Management System E
Decision Support System for management activities like, monitoring & control,
decision support and strategic planning etc.
In the real world environment, Information flow in the organization is horizontal (between
various applications) as well as vertical (across hierarchically organized departments /
branches etc). Thus in an organization, Information System can be designed at different
levels as follows:
Department Level
Organization Level
Intra-organization Level
MS-Access
Efficiency & effectiveness of any Information System very much depends upon the
organization of data files in a data bank, and the procedures adopted for data
management In this chapter basics of data management will be covered.
Data Redundancy: Since, each application has its own data files, the other users
within the department / organization can not have access to these data files. Thus
for every application separate data files are maintained, even if they are common.
This causes data redundancy, and wastage of storage space.
2.
3.
Data Isolation: The data files of common use, can not be made available for
sharing, even if desired so.
4.
5.
Data Dependency : The coding in applications is very much dependent upon the
data files design. Any change in design of data files (say addition of a new field,
or deletion of a field) will warrant for changes to be made in the coding of
application also, which uses it. .
MS-Access
6.
E Database Approach
The Database technology allows logical grouping ( the way, the user wants to view it,
as per specific needs of an application) of data files associated with different applications
in such a way, that the above mentioned problems associated with conventional way of
data management are minimized.
A database can be defined as follows:
Database is a databank, which is managed by a single agency, and it consists of
inter-related files, in which data items are organized in such a way that one can
have random access to data, as per specific needs of the users.
Important terms associated with a database are:
Field: It is the smallest unit of data, which can be stored in a database. For example, a
students name in a universitys database would appear in the field named as
student_name. Usually the data types in a filed are Numeric, Character string, Date,
Memo, Logical, Hyperlink, Picture etc. The field is at times referred as attribute/data
element / data item also. These nomenclatures can be used synonymously.
Record: It is a collection of related stored fields. A student record may consist of
collection of fields like Students name, the course taken, the date of birth, contact
address and the grade etc.
File (Table): It is a collection of different occurrences of same type of stored record.
A file is usually referred as a Table also, it describes an entity (something, about
which data is to be stored).
MS-Access
Database: A logical grouping of related files would constitute a database. For example,
A Student file in a database may be linked to another file say Library books issue,
which keeps record of books issues to students. The two files can be linked together by
a common field say Student code, which will get reflected in Student file, as well as
Library books issue file.
Primary Key: Every record in a file usually contains at least one field that uniquely
identifies that record for the purpose of data retrieval, and updating of values of fields
corresponding to a record. This identifier field is called the primary key, and it always
has a unique value. Combination of more that one fields to act as identifier of a record
is called Composite Primary Key.
Foreign Key: For setting relationship between two tables, there should be at least one
common field in two tables. Usually that common field is Primary key in one table, and
it is called Foreign key in the second table. Foreign key can have repeated values also.
1.
2.
Network: The network database model creates relationships among data through
a linked-list structure in which subordinate records (called members) can be linked
to more than one data elements (called an owner).
The way user wants to view it as per specific needs of the application
MS-Access
3.
Relational: The relational database model is based on the simple concept of flat
tables consisting of rows and columns. In this model, a table is equivalent to a
file, row is equivalent to a record, and each column is equivalent to a field.
Relations between different tables can be set through common fields.
Model
Advantages
Disadvantages
Network database
Relational database
MS-Access
1.
2.
3.
Hypermedia: Stores chunks information in the form of nodes, for which links are
established by the user, as per specific needs.
4.
5.
Centralized: A centralized database has all the related files in one physical
location. Even the processing of data is done at the centralized location. Users can
have access to the database application from remote computers / terminals.
2.
Stand alone: A stand alone database has all the related files and the procedures
for processing the data at one physical location only. Others can not have access
to the database application.
3.
MS-Access
MS-Access
Introduction
Between the physical database (i.e. the data actually stored on a physical media) and
the users( people, who access or update data), there is a need to follow standard
procedures for data manipulation (additions/deletions/updations) & data retrieval. The
database application developers should be able to integrate these procedures with their
application procedures, as per their specific needs. A set of such procedures is called
Database Management System (DBMS).
In computer terminology, DBMS is defined as a software tool, used by computers to
achieve the orderly storage of data, its processing and retrieval.
1.
2.
3.
4.
5.
6.
Processing of user queries and presentation of results in tabulated form or predesigned reports form
Components of DBMS
1.
Data Model: It defines the way, the database is conceptually designed for setting
relationship between fields, records and files.
MS-Access
2.
Data Definition Language (DDL): It defines the structure of database, and the
way how, each data item appears in the database. DDL provides link between
logical and physical views of the database.
3.
4.
Structured Query Language( SQL): It is the most popular Relational Database language, which allows the user to request for required information in most
natural way. It actually combines both DML & DDL features of DBMS. The
syntax of SQL commands is independent of Relational database brand.
5.
Data Dictionary: It stores definitions of data fields, their standard names, aliases,
associated business functions, data ownership details etc. Data Dictionary helps
in maintaining data consistency, enforcement of standards, avoid duplicacy. It
also enables independence of applications design from database design.
Name of DBMS
Database Architecture
MS Access
Oracle
SQL Server
UNIFY
Visual Foxpro
MS-Access
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
Conceptual Design
To begin with, one needs to be clear about the Information System requirements, for
which database and the procedures are to be designed. This can be done by adopting
systematic technique2 for structured analysis. The output of this process is known as
System Requirements Specifications (SRS). It mainly consists of:
1.
2.
3.
4.
5.
2
10
MS-Access
6.
7.
8.
9.
10.
M
Gets issued
Books
11
MS-Access
2.
Normalization:
The next step is to list out various attributes of the entities and their relationships.
There will be some common attributes, and some dependent attributes. These
attributes ( which can be referred as data elements also) are analyzed to minimize
redundancy, and maximize integrity. This process of analysis is called
Normalization.
After the normalization process, various tables are identified, which constitute
record structure with grouped data elements. The identified tables are linked
through common data elements. These common data elements are defined as
Primary key / Foreign Key / Composite primary key .
In our example of Library Information System, the following tables will be
identified as an output of conceptual design.
1.
2.
Books table consisting of fields, Book-code, Book name, Author, cost, edition,
Accession no. etc..
Here book-code is primary key, which is unique
3.
12
MS-Access
Graphical Illustration:
Student Table
Student- Student
Name
Code
1
Shayam
Class
Date of birth
Address
Email- address
1st
Year
11/05/1985
shayam@yahoo.com
Ashish
2nd
Year
21/07/84
3
4
----
----
----
ashish@hotmail.com
-----
Issue Table
StudentCode
1
1
2
Issue-date
Status
1
2
2
12/10/2001
14/08/2002
14/08/2002
Returned
Book Name
Visual Basic
MS Access-An
Overview
---
Author
I.K. Jain
R.P. Singh
Edition
1998
1997
Cost
500
200
---
---
---
Book-Code
Books Table
Book-code
1
2
3
13
MS-Access
Physical Design
In the physical design, the actual structures of tables are created using a particular DBMS
package. The physical design shows how the files, records, fields are actually stored on
the physical storage media, depending upon the type of database, the DBMS supports.
This physical design giving complete logical view ( the way user wants to view it) of
the database, is called schema.
Various applications developers have the choice of getting different logical views (which
may be even partial) of the same database. They can customize these views as per their
specific needs. Such logical view is called subschema. DBMS provides tools for
creating the subschemas .
This characteristic of DBMS makes the database design independent of
applications design. That means, any changes made in the database design will not
affect already working applications, unless the data elements, being used by them
are deleted from the database.
14
MS-Access
15
MS-Access
q Case Study
1.
2.
3.
Year end processing to add Earned leave and initialize Casual Leave balance.
4.
5.
6.
16
MS-Access
7.
8.
9.
Employee details
Leave details
Leave details:
Employee
10.
Takes
Leave
After Normalization process, we will get the conceptual design in the form
of the following two tables.
Employee table consisting of fields: Employee-code, Name, Designation, Date
of Joining, Skill, EL at credit, CL at credit, RH at credit,
HPL at credit, Salary, Email address, employee
photograph etc.
17
MS-Access
Reports Page
Employee Report
18
MS-Access
Few suggested enhancements to the above mentioned case study, which can be
done by participants as assignment.
Add login screen for screen for maintaining employee data to enforce Access
controls.
Add a filed in Leave table to set hyperlink to leave sanction order (MS Word
file).
Generate MS Word document for leave details statement for every employee
with a provision to send it as an attachment to email of that employee (You cal
use Mail merge option).
Create a new table containing department code, and other details. In employee
table, add a field for department, to which employee belongs. In the properties
of this field, pickup the values for department field from the department table
through lookup Wizard.
Develop a module for periodic backup of tables. This process should get triggered,
on mouse click on the main menu.
Develop a module for automatic backup of tables. This process should get
triggered, automatically on 1st day of every month.
On the similar lines of the case study, you can also develop a database application
relevant to your work area.
19
MS-Access
q Starting MS Access
Figure 1
Select Blank Access database option. The dialog box shown in Figure 2 will
appear.
20
MS-Access
Figure 2
To open table
for data entry
To make modification
in design of table
Figure 3
21
MS-Access
After the database has been created, different objects of the database like Tables, Queries,
Forms, Reports etc. can be created by selecting appropriate tabs.
Note: We are going to refer to this database window in later part of the workbook also.
In this option, table has to be created from scratch, in which its fields names, their data
types and properties have to be entered.
In this option, wizard dialog box will open with the steps provided to create a table.
In this option, only data has to be entered and it will take fields names as field1, field2
and so on and data type it will take automatically based upon data entered (one can
rename the fields names, if required).
22
MS-Access
Figure 4
As shown in Figure 5, enter names of fields in Field Name column, type of data
to be entered in fields in Data Type column and enter description of fields in
Description column if required.
Figure 5
23
MS-Access
Figure 6
Type the Table name as Employee and click OK. The dialog box as shown in
Figure 7 will appear.
Figure 7
24
MS-Access
Figure 8
Start entering the data from the cursor placed at the first blank record .
The following data may be entered as shown in Figure 9.
Figure 9
E Deleting Records
Figure 10
25
MS-Access
Click Edit>>Delete Record from the menu bar, the record will be deleted.
Note : To delete all record, click Edit>>Select All and press Delete button. But
dont try this option otherwise you will lose whole data of that table.
Locating Data
Select the field where the data has to be searched, by clicking the Field Heading
OR put the cursor anywhere in the column where the data has to be searched.
Click Edit>>Find. The Find and Replace dialog box appears as shown in
Figure 11.
Click here to select the field.
Figure 11
26
MS-Access
Enter a string to search for, in the Find What: option, say ANIL.
In Match option, select any of the three category provided.
Choose Find Next to search for more records.
Select Cancel to stop the search and close the dialog box.
Click on the field name where the data is to be replaced. For example, click on
Designation field
Select Edit>>Replace.
The Replace dialog box as shown in Figure 12 will appear.
Figure 12
27
MS-Access
E Sorting Data
Data stored in a table can be sorted on text, numbers, or date fields in ascending order
(A to Z, zero to 9, or earliest to latest date). Or, you can sort in descending order (Z to A,
9 to zero, or latest to earliest date).
Figure 13
The table will open in Design View. The design of the fields in table can now be modified,
i.e., the fields can be deleted, added or changed according to the requirements. After
the modification, changes can be saved and the database window reappears.
28
MS-Access
E Primary Key
A Primary Key is a field (or group of fields) that uniquely identifies each record. When
primary key is created, Access will do the following things:
1.
2.
3.
Make sure no two records in the table have the same value in the field (or group of
fields) that defines the primary key.
Keep records sorted (ordered) by the entries in the primary key.
Speed up processing.
Note: No field that is part of a primary key can be left blank during data entry.
Select the field for which primary key property has to be set.
key icon
row selector
Figure 14
Note: If the data in a table contains duplicate data for the emp_code field, the error
message will be displayed while defining the emp_code field as a primary key. To
remove the error, first remove the duplicate data and then define field as a primary
key.
29
MS-Access
Select the field for which primary key setting has to be removed.
Click Edit>>Primary Key. It will remove primary key setting.
Number
Text
Date
Number
Date
It may be noted that the values of Emp-code should be the same as those already
mentioned in the Employee table.
30
MS-Access
q Relationships
In RDBMS systems, usually data is stored in more than one table, depending on the
type of information. To bring the relevant information together in a Form/Report/Query,
these tables need to be linked together.
To link the tables together Relationships are used. For example, there are two tables
Employee table, which contains employees details, and other Leave table, which contains
the information about the leaves taken by all the employees. To create a report, which
will give the details of the leaves taken by all the employees, relationship between the
two tables Employee and Leave is required. Sample report having data from both the
tables is shown in Figure 15.
Figure 15
E How it works ?
In the above example, the fields in both tables must be linked so that they show relevant
information about the employees. This linking is done by setting relationships between
tables. A relationship is created by matching data in one of the fields of the table
usually a field with the same name in both tables. In most cases, these matching fields
Training Division, NIC, New Delhi
31
MS-Access
are the primary key3 from one table and a foreign key4 in the other table. For example,
employees can be associated with the leaves they have taken by creating a relationship
between the Employee table and the Leave table using the Emp_code (Employee Code)
field as shown in Figure 16.
Primary Key
Employee Table
Foreign Key
Leave Table
Figure 16
Entity-Relationship diagram
Employee Tables
Emp_code
Takes Leave
Leave Tables
Emp_code
Primary key consists of one or more fields (columns) whose value or values uniquely identify each
record in a table. A primary key cannot allow Null values and is used to relate the table to foreign keys in
other tables.
4
Foreign key is one or more table fields (columns) that refer to the primary key field or fields in another
table. A foreign key indicates how the tables are related. The data in the foreign key and primary key
fields must match, though the field names do not have to be the same.
32
MS-Access
Types of Relationship
1.
A one-to-many relationship :
A many-to-many relationship
In a many-to-many relationship, a record in the first table can have many matching
records in the second table, and a record in the second table can have many matching
records in the first table. This type of relationship is only possible by defining a third
table (called a junction table) whose primary key consists of two fields the foreign
keys from both the tables, first and second. A many-to-many relationship is actually
defining two one-to-many relationships with a third table. For example, the Leave
table and the Training table have a many-to-many relationship thats defined by
creating two, one-to-many relationships to the Employee table.
3.
A one-to-one relationship
In a one-to-one relationship, each record in the first table can have only one matching
record in the second table, and each record in the second table can have only one
matching record in the first table. This type of relationship is not common, because
most of the information related in this way would be in one table. You might use a
one-to-one relationship to divide a table with many fields, to isolate part of a table for
security reasons, or to store information that applies only to a subset of the main
table.
Close any tables you have opened since relationships cant be created or modified
between open tables.
Click Tools>>Relationships. Blank screen will appear.
33
MS-Access
Figure 17
Similarly you can add more tables depending upon the requirement.
Figure 18
Drag the Emp_code of Employee table over Emp_code of Leave table to relate
them. Edit Relationships dialog box will appear as shown in Figure 19.
34
MS-Access
Figure 19
Click Create. A line joining the two tables will appear as shown in Figure 20.
Figure 20
The above two steps can be repeated for each pair of tables you want to relate.
Close the Relationships window. The system will prompt for the Saving of
Relationship.
Click Yes.
Note: If you drag a field that isnt a primary key and doesnt have a unique index to
another field that isnt a primary key and doesnt have a unique index, an indeterminate
relationship is created.
35
MS-Access
Click Tools>>Relationships.
Double click on the middle of the relationship line. Edit Relationship dialog box
will appear as shown in Figure 21.
Figure 21
Click the Join Type. button, and then click the desired join type from the Join
Properties dialog box as shown in Figure 22.
36
MS-Access
Figure 22
Click OK.
Deleting Relationship
Click Tools>>Relationships.
Click on the Relationship line to be deleted.
Press Delete key.
Click Tools>>Relationships.
Click on the table to be deleted.
Press Delete key.
37
MS-Access
Referential Integrity
Referential integrity is a system of rules that Microsoft Access uses to ensure that
relationships between records in related tables are valid, and that you dont accidentally
delete or change related data.
Basic requirement for setting up referential integrity:
1.
The matching field from the primary table is a primary key or has a unique
index.
2.
The related fields have the same data type.
3.
Both tables belong to the same Microsoft Access database.
When referential integrity is enforced, you must observe the following rules:
1.
You cant enter a value in the foreign key field of the related table that doesnt
exist in the primary key of the primary table.
2.
You cant delete a record from a primary table if matching records exist in a
related table. For example, you cant delete an employee record from the
Employees table if there are leave details for that employee in the Leave Table.
If at all it is required to delete a record in Employee table, one should just delete
the corresponding leave details from the Leave table.
3.
You cant change a primary key value in the primary table, if that record has
related records.
Setting Referential Integrity
Open the relationship in edit mode as already discussed in Editing the Existing
Relationship section.
Changing a primary key value in the primary table automatically updates the matching value in all
related records.
6
Deleting a record in the primary table deletes any related records in the related table.
38
MS-Access
q Query
A query is logical view of selected data elements from tables as per the specific needs
of the user (which is called subschema). Query option is used for the purpose of display,
updating or analysis of data.
E Simple Query
Figure 23
The Show Table dialog box lets you select the tables/queries/both for creating a query.
39
MS-Access
Figure 24
Figure 25
Note: From the database window also the query can be run. Click on Queries tab,
choose the query as Employee_query and click on Open button.
40
MS-Access
Expression to calculate DA
Figure 26
Note: For creating the expression, Expression Builder can be used. Right-click in the
Field cell where you have to add the calculated field, and then click Build.
Select Query>>Run to see the output. The calculated value for DA, with the
field name DA, will be displayed in the output of query.
Close the Query window.
41
MS-Access
In a design grid of query, enter an expression in the criteria cell for the field.
The expression in the preceding example would be SA as shown in Figure 27.
Note : Additional criteria can be entered for the same field or different fields using
either the And or the Or operator. For And operator, the expressions are in different
cells in the same row. For Or operator, the expressions are in different rows of the
design grid.
Figure 27
Select Query>>Run. The output contains only those records having Designation
equal to SA.
42
MS-Access
E Parameter Queries
A parameter query is a query that while running displays its own dialog box prompting
you for information, such as criteria for retrieving records or a value you want to insert
in a field. You can design the query to prompt you for more than one piece of information;
for example, you can design it to prompt you for two dates. Microsoft Access can then
retrieve all records that fall between those two dates.
In query Design view, drag the fields from the field list to the query design grid.
In the Criteria cell for the field you want to use as a parameter, type a prompt
enclosed in square brackets as shown in Figure 28.
Figure 28
The prompt Type Employee Code will be displayed when you run the query as
shown in Figure 29.
Figure 29
Enter the value for employee code and click OK. It will display the output having
emp_code, name, designation, salary and DA for the corresponding employee code.
43
MS-Access
E Action Queries
An action query is a query that makes changes to many records in just one operation.
The action queries are of four types: delete, update, make-table, and append queries
Delete Query
Delete Query deletes a group of records from one or more tables. With delete queries,
always entire records will be deleted, not just selected fields within records. Single
delete query is used to delete records from a single table or from multiple tables, if
relation has been set between the tables, in a one-to-one relationship or a one-to-many
relationship.
Drag the asterisk(*) from the field list for the table, from which records are to be
deleted, to the query design grid.
Add field and table to the design grid for which criteria for deleting records has to
be specified. Where appears in the Delete cell under this field. In the Criteria
cell for the fields, criteria has to be typed as shown in the Figure 30.
44
MS-Access
Figure 30
Note: If Delete Query is used for One-to-many relations, records will be deleted
from all the related tables. For example, tables Employee and Leave are having oneto-many relationship (select the Cascade delete related records option while setting
the relationship.)
In this case, the Delete Query will delete the records from both the tables related, if
the Salary is less than 9500.
To see a list of the records going to be deleted, click View >>Datasheet view. To
return to query Design view, click View >>Design View.
45
MS-Access
Update Query
Create an update query, selecting the tables or queries that include the records
you want to update and the fields you want to use for setting criteria.
In query Design view, click the Query>>Update Query.
Drag from the field list to the query design grid the fields you want to update or
you want to specify criteria for.
In the Criteria cell, specify the criteria if necessary.
In the Update To cell for the fields you want to update, type the expression or
value you want to use to change the fields, as shown in Figure 31.
Figure 31
To see a list of the records that will be updated, click View >>Datasheet View.
This list wont show the new values. To return to query Design view, click
View >> Design View.
Click Query>>Run to make the table updated.
46
MS-Access
Create an update query that contains the table you want to update and the table
whose values you want to copy.
If the tables arent already joined, join them on the fields that have related information.
For example, if you want to copy data from the Name field of the Employee table to a
field in Leave table, join the two tables on the primary key, which in this case is
Emp_code.
In the Update To cell for the fields you want to update, type an expression with
the following syntax: [tablename].[fieldname], where tablename and fieldname
are the names of the table and field that contain the data youre copying. For
example, if you are copying data from the Name field of the Employee table, you
would type [Employee].[Name] in the Update To cell as shown in Figure 32.
Figure 32
Click Query>>Run. It will copy the data from Name field of Employee table to
the Name field of the Leave table. (To see the updated table, you may see the
Leave table in Datasheet view).
47
MS-Access
Make-table Query
Create a query, selecting the tables or queries that contain the records you want
to put in the new table.
In query Design view, click Query >> Make-Table query. The Make Table
dialog box appears.
In the Table Name box, enter the name of the table you want to create or replace.
For example, to create new table employee_new, type that name in the Table
Name box.
Click Current Database to put the new table in the currently open database. Or
click Another Database if you want to create table in a new database and type
the name of the database you want to put the new table in. Type the path if
necessary.
Click OK.
Drag from the field list to the query design grid the fields you want in the new
table.
In the Criteria cell for the fields that youve dragged to the grid, type the criteria
as shown in Figure 33.
Figure 33
48
MS-Access
For the preview the new table before you actually create it, click the View>>
datasheet view. Return to query Design view by clicking View>>Design View.
To create a new table, click Query>>Run. It will copy all the fields shown in
Figure 33 and its data to the newly created table employee_new.
Append Query
This query is used to append records from one table to another table using an append
query.
Create a query that contains the table whose records you want to append to another
table (can be done using Simple Query Wizard option).
Open the query created in the above step in design mode.
Click Query>>Append Query. The Append dialog box appears as shown in
Figure 34.
Figure 34
In the Table Name box, enter the name of the table you want to append records
to.
Click Current Database if the table is in the currently open database. Or click
Another Database and type the name of the database where the table is stored.
Type the path if necessary.
Click OK.
49
MS-Access
In Append To option, select the Field name of the table where the data has to be
appended and in Criteria cell for appending the field value as shown in
Figure 35.
Figure 35
If all the fields in both tables have the same names, you can just drag the asterisk
(*) to the query design grid. However, if youre working in a database replica,
youll need to add all the fields instead.
If the fields youve selected have the same name in both tables, Microsoft Access
automatically fills the matching name in the Append To row. If the fields in the
two tables dont have the same name, in the Append To row, enter the names of
the fields in the table youre appending to.
In the Criteria cell for the fields that you have dragged to the grid, type the
criteria on which additions will be made.
Click Query>>Run to execute the query.
Note : So far, the practice for basics of Queries has been done. For further details, you
may continue through the following pages, else go to the Section on Forms on Page 59.
50
MS-Access
Cross-tab Query
Cross-tab queries let you cross-tabulate data in a row-by-column fashion. The example
shown below answers the question Who took how many leaves of what type ?.
Note : To quickly create Cross-tab query of data in a single table, Crosstab query
Wizard can be used.
Figure 36
In the design grid of query, specify which fields values become column headings,
which fields values become row headings, and the summary values and how you want
to summarize the value (for example, sum, average, count, or otherwise calculate).
Steps for creating Cross-tab query are as follows:
Choose Row Heading in the Crosstab cell for the field you want to use for row
heading. More than one field can be designated, but at least one field must be
Group By in its Total Cell as shown in Figure 37. Expressions can also be used to
group the value together.
51
MS-Access
Choose Column Heading in the Crosstab cell for the field you want to use for
column heading. Only one field is allowed and it must contain Group By in its
Total Cell as shown in Figure 37. Expressions can also be used to group the value
together.
Choose the summary value in the Crosstab cell for the field you want to summarise.
In the Total Cell, choose the summary (usually it is Sum or Average). Dont
choose Group By for this field.
Other fields can also be chosen in Crosstab cell, you want to group by, without
displaying them in result.
Click View>>Datasheet View to view the result.
For the setting in design grid of query, result is shown in Figure 37.
These settings
display the total
of leaves.
Figure 37
52
MS-Access
An SQL query is a query that is created using an SQL statement. Examples of SQLspecific queries are:
Union Query
This type of query combines fields (columns) from one or more tables or queries into
one field or column in the querys results. For example, NIC Cell in ministries have to
give the attendance report of its staff each month to NIC HQ. These lists from all
ministries can be combined into one result set using a union query, and then create a
make-table query based on the union query to make a new table. For example NIC HQ
is getting the attendance list from two ministries Minis1 and Minis2. These two lists
can be combined through union query.
The two tables Minis1 and Minis2 are shown in Figure 38.
Figure 38
For Union Query, select Queries >>New then click Design View>>OK.
Add tables minis1 and minis2.
Click on Query>>SQL Specific>>Union.
53
MS-Access
A Union Query window is opened. Type the SQL statement given below:
SELECT [EMPCODE],[ATTENDENCE] FROM MINIS1 WHERE MONTH=JANUARY
UNION SELECT [EMPCODE], [ATTENDENCE] FROM MINIS2 WHERE
MONTH=JANUARY;
Click Query>>Run.
Figure 39
Pass-through Query
This type of query sends commands directly to ODBC databases, such as Microsoft
SQL Server, using commands that are accepted by the server. For example, pass-through
query can be used to retrieve records or change data.
Data-definition Query
This type of query creates or alters database objects, such as Microsoft Access or
Microsoft SQL Server tables.
54
MS-Access
Subquery
This type of query consists of a SQL SELECT statement inside another select query or
action query. These statements can be entered in the Field row of the query design grid
to define a new field, or in the Criteria row to define criteria for a field.
Add table Employee for this query and write the following SQL statement:
Type Sushila in criteria row and in name column as shown in Figure 40.
Figure 40
55
MS-Access
Figure 41
In the example shown in Figure 41, two tables Employee and Leave are used with the
relationship set on the field emp_code. In this Query, Emp_code and Name from
Employee table and duration from Leave table is selected where the emp_code of both
the tables are equal.
Figure 42
56
MS-Access
Figure 43
Create combo box having all the Designation from the designation field of the
table.
Create a query, Query new having all the required fields to display and in Criteria
cell of Designation field give criteria [forms]![form1]![combo1]
Create Button and in Command button wizard, select category Miscellaneous
and action Run Query.
Here forms mean that a form is called. Form1 is the form name. Combo1 is the field
from where value is taken for criteria.
The design view of query is shown in Figure 44.
Figure 44
57
MS-Access
Run the form and enter the value for designation and click button Run Query.
Output will be displayed as shown in Figure 45.
Figure 45
58
MS-Access
q Forms
A form is a graphical user interface, which can be customized as per user requirements
and is used for the following purposes:
To create custom dialog box to accept user input, and then carry out an action
based on that input.
Figure 46
59
MS-Access
The form will be opened in the Form View mode as shown in Figure 47.
Figure 47
Note : Modification in the form can be done in the Design view of the form. To go in
design view of form, click View>>Design View.
A form can take the data from table or query for viewing and editing purpose.
60
MS-Access
Note : If the form wont contain data (for example, if you want to create a form to
use as a switchboard to open other forms or reports, or if you want to create a custom
dialog box), dont select any Table or Query from this list.
Figure 48
This will give the field list as shown in Figure 49. The required fields can be dragged on
to the form. Form will appear as shown in Figure 49.
61
MS-Access
Field List
Figure 49
From the Database window, double click the empform you will be able to see
different records from the form, as shown in Figure 50.
Figure 50
62
MS-Access
E Different Controls
In a form, we can also introduce many controls. Various controls (like label, textbox,
combobox, command button, tab etc.) available on the tool bar as shown in Figure 51,
can be put on the form.
Figure 51
Label
Label on a form or report is used to display descriptive text such as titles, captions, or
brief instructions. Labels do not display values from fields or expressions; theyre always
unbound and they dont change as you move from record to record.
On the form, click where you want to place the label, and drag the mouse.
Text boxes
Text boxes are drawn on a form or report to display data from a table, query, or SQL
statement. This type of text box is called a bound text box because its bound to data in
a field. Text boxes can also be unbound8 . For example, you can create an unbound text
box (i.e. text box isnt bound to the data in field) to display the results of a calculation,
or to accept input from a user.
8
63
MS-Access
Click View>>Field List. Drag the field(s) from the field list and position them on
the form.
Create an unbound Text box
Click anywhere on the form to create a default-sized text box, or drag to create a
text box thats the size you want.
Create a Text box for computed Fields (for numeric and text entries)
Open a form in Design view and select a table from the New form dialog box
Click the textbox tool in the toolbox. Click on the form where the control has to
be placed and do the following:Note: A text box is the most common type of control used to display a calculated
value, but you can use any control that has a Control Source property.
Type the expression in the Control Source property of the textbox. For example,
for the calculation of DA, type expression = [salary] * 0.43 in the Text box.
Note: To use the Expression Builder to create the expression, click View>>Properties
to open the controls property sheet, and then type the expression in the Control
Source property box or click the Build button to open the Expression Builder.
64
with a wizard
MS-Access
Figure 52
Follow the directions in the wizard dialog boxes. In the last dialog box, click
Finish to display the command button in Design view. You may introduce many
buttons on the form like this.
The view of buttons will appear as shown in Figure 53.
Figure 53
65
MS-Access
List box or combo box is quicker and easier way to select a value from a list than to
remember a value to type. The list in a list box consists of rows of data. Rows can have
one or more columns, which can appear with or without headings.
If data type of field is Lookup field in table
In form Design view, click view>>Field List and then drag the Lookup field
from the field list to the form. Microsoft Access automatically creates the lookup
list box or combo box.
OR
If data type of field is not a Lookup field in table .
Switch to Form view to test the list box or combo box. It will appear as shown in
Figure 54.
Figure 54
66
MS-Access
Figure 55
The steps to remove the navigation bar from the view of the form, are as follows:
Open the form properties by right clicking the mouse button by placing the cursor
at left most corner of the form in design view as indicated by arrow. It will appear
as shown in Figure 56.
Click here to
open form
property
dialog box.
Figure 56
In the form properties, select Navigation Button option to NO. The view of the
form will appear without navigation bar at the bottom
67
MS-Access
Creating Subforms
A subform is a form within a form. The primary form is called the main form, and the
form within the form is called the subform. A form/subform combination is often referred
to as a hierarchical form, a master/detail form, or a parent/child form.
Subforms are especially effective when data has to be shown from tables or queries
with a one-to-many relationship.
Figure 57
In this figure, a subform is created using table personalinfo having one to many
relationships with the table Training.
68
MS-Access
Figure 58
Note: To change the name of a Page tab, double-click the page (Page1 or Page2) to
open its property sheet, and then specify a new name in the Caption property. If you
dont specify a name in the Caption property, Microsoft Access uses the setting in
the Name property.
To add, delete, or change the order of tabs, click the border of the tab control with
the right mouse button and click Insert Page, Delete Page, or Page Order.
69
MS-Access
Create a new object by selecting Create New or use the already existing object
by selecting Create from File option.
Check the Display As Icon option
In the Object type dialog box, select Sound.
Select OK.
In a view of form or subform or datasheet, select the entire contents of that field
on which filters results is based.
Select the value in form view or database view (as shown in figure, the
Designation value SSA is selected for filter) and then click Filter By Selection
on the toolbar. The output of the form will appear as shown in Figure 59.
Figure 59
70
MS-Access
Hyperlinks can be used in forms and datasheets to jump to objects in the same or another
Microsoft Access database, to documents created with Microsoft Word, Microsoft Excel,
and Microsoft PowerPoint, and to documents on the global Internet or on a local
intranet.
The hyperlinks can be created on a form in different ways.
Create a field to store hyperlinks that will change for each record
Figure 60
71
MS-Access
Figure 61
Note : The hyperlink can be followed from the datasheet view of the form.
72
MS-Access
73
MS-Access
Creating Sections
The effectiveness of a form can be increased by adding one or more sections. Most
forms have just a detail section, but a form can also include form header, page header,
page footer, and form footer sections.
To insert Form Header/Footer And Page Header/Footer
74
MS-Access
Figure 62
75
MS-Access
q Reports
A report is an effective way to present data in a required printed format because of
control over the size and appearance of objects on a report. Most of the information in a
report comes from an underlying table, query, or SQL statement, which is the source of
the reports data. Other information in the report is stored in the reports design.
Select New.
The New Report dialog box appears as shown in Figure 63.
Figure 63
76
MS-Access
Access gives various options for report creation. Report Wizard automatically creates a
report based on the selected fields of the table/query selected.
Figure 64
77
MS-Access
Figure 65
9
Figure 66
9
Reports based on grouping levels and sort order will be explained later in the section.
78
MS-Access
If sort order of records is not required, click on Next and you get the screen to
decide the layout of the report as shown in Figure 67.
Figure 67
Figure 68
79
MS-Access
Figure 69
Clicking on Finish, shows the Preview of the Report as shown in Figure 70 and
the report file will be saved with same name as the title of report which can be
changed.
Figure 70
Report created using wizard option can be modified as and when required by going in
design view of that report.
80
MS-Access
Figure 71
Click View>> Print Preview to get preview of the report as shown in Figure 72.
81
MS-Access
Figure 72
Select the table or query that contains the data for the labels, and then click OK.
Follow the instructions in the wizard dialog boxes. The output of this report will
be as shown in Figure 73.
82
MS-Access
Figure 73
To include a calculated field, create a text box in the Detail section of the report
in the design view.
Write the expression for calculation in the Text box. Results would be displayed
in Print Preview
For example, if we have to calculate DA from the Basic of the employee, the expression in the text boxes for DA will be =[basic]*0.42
Records in a report can be arranged in certain order depending on the sorting and grouping
order defined. A report can be sorted on upto a maximum of 10 fields or expressions.
83
MS-Access
In the first row of the Field/Expression column, select a field name, or type an
expression as shown in Figure 74.
Figure 74
The field or expression in the first row is the first sorting level (the largest set). The
second row is the second sorting level, and so on upto 10 sorting levels can be defined.
For each sorting level, sort order can be defined as Ascending or Descending.
Click the field or expression whose group properties you want to set.
Set the group properties in the following list.
For each field defined in the sorting order, group properties can be defined.
Either Group Header or Group Footer should be set to Yes in order to create
a group level.
84
MS-Access
GroupOn. Specifies the value or range of values that starts a new group. The
options you see depend on the data type of the field on which youre grouping. If
you group on an expression, you see all the options for all data types.
GroupInterval. Specifies any interval that is valid for the values in the field or
expression youre grouping on.
Keep Together. Keeps groups together on one page.
Figure 75
The design view of the form will be appear as shown in Figure 76.
Figure 76
85
MS-Access
Note: When designing a report, the field on which grouping is to be done should be
kept in Group Header section not in Detail section as Designation field is kept in
Designation header section.
The output will be appear as shown in Figure 77.
Figure 77
86
MS-Access
Figure 78
Note: Expression for the running sum can be given for more than one field in report
footer.
The output of this report will appear as shown in Figure 79.
87
MS-Access
Figure 79
88
MS-Access
Figure 80
The output for this design view appears as shown in Figure 81.
Figure 81
Note: To give S.NO. groupwise, place the text box in a group header and in the
Text box property sheet, set RunningSum as OverGroup and ControlSource
Property = 1.
Training Division, NIC, New Delhi
89
MS-Access
A multiple-column report can be used to print the report in more than one column. In
this case Report Header/Footer and Page Header/Footer span the full width of the
report, while Group Header/Footer and Detail Section span the width of one column.
For example, if you want to print the data in two three-inch columns, place the controls
within the width of one column; in other words, place the controls in the first three
inches of these sections in Design view.
Note : If you left space between the last control in the detail section and the bottom
edge of the detail section, you can leave Row Spacing set to 0.
In the Column Spacing box, type the amount of space you want between the
columns.
Under Column Size, type the width you want for a column in the Width box; for
example, 3. You can set the height of the detail section by typing a number in the
Height box or by adjusting the height of the section in Design view.
Under Column Layout, click suitable option as shown in Figure 82.
Click the Page tab of the Page Set-up dialog box
Under Orientation, click Portrait or Landscape.
Click OK.
90
MS-Access
Figure 82
Figure 83
91
MS-Access
Crosstab Report
Cross-tab Report is based on a Cross-tab query meant for analysing the data in a
cross-tab format.
In the ColumnHeadings property box, type the column headings you want to
appear in the report, separating each one with a semicolon. If a column heading
contains spaces, enclose it in double ( ) quotation marks. For instance, in a
query showing sales by quarter, you would type:
CL Taken;El Taken;Medical Taken
Add the controls for the fields you want to appear in the report.
Place labels for the row headings and column headings in the page header.
Place text boxes for the row headings and column values in the detail section.
The report thus obtained is shown in Figure 84.
Figure 84
92
MS-Access
Open the database containing forms, reports or other objects already created.
Click Yes. The following dialog box will appear as shown in Figure 85.
Figure 85
93
MS-Access
Click Edit button of Switchboard page (shown in Figure 85) to create all the
switchboard items of that page. The dialog box appeared as shown in Figure 86.
Figure 86
Click New button to add switchboard items to this page. The dialog box appears
as shown in Figure 87.
Figure 87
In the Edit Switchboard Item dialog box, in the Text: field, type the text that is
to be displayed for the Switchboard Item on the Switchboard page.
Select the Command: to be executed.
Depending on the selection of command, the next field of the dialog box changes.
94
MS-Access
Figure 88
Click OK.
More items can be added to this Switchboard by clicking on New button in the
Edit Switchboard Page dialog box and entering the information as done for the
previous item. Table 1 shows the various items that can be added to this page.
SN SWITCHBOARD SWITCHBOARD
PAGE
PAGE ITEMS
COMMANDS
OBJECTS TO
BE EXECUTED
1
Main Switchboard
1.1
Enter Employees
Open form in
Details
add mode
1.2
Enter Leave Details Open form in
add mode
1.3
Employee report
Open report
1.4
1.5
Employee
(Form name)
Leave
(Form name)
Employee
(Report name)
Open Report
Leave_detail
(report name)
Exit Application
Click Close, after adding all the switchboard items to the Edit Switchboard Page.
Click Close Button of the Switchboard Manager Dialog box. You come back to
database window.
95
MS-Access
Once the Switchboard is made, one form named Switchboard and a table named
Switchboard items will appear in the database window in their respective objects.
The Switchboard page for the above items will be appeared as shown in Figure 89.
Switchboard Page
Switchboard
Page Items
Figure 89
96
MS-Access
If switchboard is created for the first time then Microsoft Access asks if youd like to
create a switchboard.
Click Yes. The Switchboard Manager dialog box appears as shown in Figure 85.
Click New in the Switchboard Manager Dialog box to add new page, the dialog
box appeared as shown in Figure 90.
Figure 90
97
MS-Access
Figure 91
Select the Switchboard page in which Items has to be added. For example, select
Main Switchboard page.
Click Edit in the Switchboard Manager dialog box to edit all the items in that
page. The Edit Switchboard dialog box will appear as shown in Figure 92.
Figure 92
98
MS-Access
Click New.
In the Edit Switchboard Item dialog box, do the following settings.
Text/List box name
Text
Command
Switchboard
Value
Maintain Employees Data
Go to Switchboard
Update Employee
Figure 93
Add rest of the items to the same switchboard by following the above three steps. The
page containing all the items will be appears as shown in Figure 94.
Figure 94
99
MS-Access
Click Close.
Similarly add all the items to the rest of the pages of the Switchboard.
Note: Block Diagram and Table 2 are provided in the following pages to add all
switchboard items and their commands for all switchboard pages.
To rearrange items
100
MS-Access
4)
Add New Employee
( To open Employee form in Add
mode)
5)
Modify Employee Data
( To open Employee form in Edit
mode)
6)
Delete Employee Data
( To run Macro,
Macro_Delele_emp_Records)
Reports Page
4)
Employee Report
(To open Report Employee )
5)
Creating Employee Label
( To open report Employee Label )
6)
Leave Details of Individual
employee
( To open report Leave )
101
MS-Access
SN
SWITCHBOARD SWITCHBOARD
PAGE
PAGE ITEMS
COMMANDS
Main
Switchboard
Maintain
Employees Data
Enter Leave
Details
Year End
Processing
Reports
Exit
Add New
Employee
Modify Employee
Data
Delete Employee
Records
Exit
Employee Report
Creating Employee
Labels
Exit
Open form in
edit mode
Run Macro
employee
Go to
Switchboard
Main
Switchboard
Update
Employees
Detail
Report
OBEJCT TO
BE EXECUTED
Macro_Delele_
emp_Records
Go to switchboard Main Switchboard
Open Report
employee
Open Report
Labels employee
102
MS-Access
Figure 95
103
MS-Access
Press Right
mouse button
in this portion
Figure 96
Press right mouse button and select properties option, following dialog box will
appear as shown in Figure 97.
Figure 97
104
Click on the Picture property, specify the picture file name with complete path.
For example, c:\Program Files\Microsoft Office\Office\Bitmaps\Dbwiz\ledger.gif.
Training Division, NIC, New Delhi
MS-Access
Figure 98
E Deleting a Switchboard
To delete Switchboard from the access database
105
MS-Access
Figure 99
Give application title name and in Display Form/Page option give default
Switchboard page name as shown in Figure 100.
Figure 100
106
Click OK.
MS-Access
Click View >> Toolbars>> Customize. Customize dialog box will appear as
shown in Figure 101.
Figure 101
Click Toolbars tab (If it is not already active) and choose New.
Type Main menu in the text box in New Toolbar dialog box as shown in
Figure 102.
Figure 102
Click OK.
107
MS-Access
Figure 103
Selecting Menu Bar in the Type: box creates Main menu with no items and it appears
on screen as shown in Figure 104.
Figure 104
108
MS-Access
Figure 105
Drag New Menu from the command list to the Main menu menu bar.
Right click on New Menu in the Main menu and type Update Employee in the
Name text box as shown in Figure 106.
Figure 106
109
MS-Access
Figure 107
In Main menu, click Update Employee menu option. An empty box will appear.
The forms would now be added to this.
To add commands to it
In the Customize dialog box, select Command tab, if not already selected.
Click All Forms from Categories.
Drag the command employee to the empty box and rename it as Add Employee.
Similarly, drag the command Leave and rename it as Leave Details.
Drag the macro designed for deleting records and rename it as Delete Employee.
The Main menu designed is shown in Figure 108.
Figure 108
Similarily other items can be added to the various menu options. For example, add
items to Year End Processing and Reports menu options.
110
MS-Access
Click Tools>>Startup.
In the Startup dialog box, select Main menu in the Menu Bar text box as shown
in Figure 109.
Figure 109
Click OK.
When database is opened, Main menu will appear as shown in Figure 110.
Figure 110
111
MS-Access
Point your mouse cursor to the database title bar and Click right mouse button.
Popup menu will appear as shown in Figure 111.
112
Click on Startup option and change the setting of the Menu Bar to Default.
Close this application and when you open database again, Default menu bar will
appear again.
MS-Access
E Exporting
Exporting is a way to output data and database objects to another database, spreadsheet,
or file format so that another database, application, or program can use the data or
database objects. The various types to which they can be exported are:
1.
Microsoft Access
2.
Dbase
3.
Excel
4.
Foxpro
5.
HTML documents
6.
Paradox
7.
Text Files
8.
Rich Text Format
9.
Microsoft IIS
10. ODBC databases
11. Microsoft Word Merge
10
113
MS-Access
Figure 112
Specify the file name as Leave and the type as Microsoft Excel 97-2000, to
which it is to be exported, in the respective text boxes.
Click Save.
Thus the data of the Leave table gets exported to an Excell worksheet named Leave.
114
MS-Access
Now this file can be opened in Ms-Excel for further editing. Any changes in Excel file
will not be reflected in data stored in MS-Access table/Query.
Note : The data from Access can be exported to other file formats, specified earlier,
in the same manner, selecting the Save As type for the desired format.
E Importing
Importing data creates a copy of its information in a new table in your Access database
or Access project. The source table or file is not altered in this process.
When importing data, you cant append data to existing tables (except when importing
spreadsheet or text files). However, once you have imported a table, in an Access database
you can perform an append query11 or in an Access project you can use a stored
procedure12 to add the tables data to another table.
You can also import database objects other than tables, such as forms or reports, from
another Access database or Access project.
The various types from which data can be imported are:
Microsoft Access
Dbase
Excel
Foxpro
HTML documents
Paradox
Text Files
ODBC databases
Exchange
11
An action query that adds the records in a querys result set to the end of an existing table.
12
A precompiled collection of SQL statements and optional control-of-flow statements stored under a
name and processed as a unit. Stored procedures are stored in an SQL database such as Microsoft SQL
Server, usually on a server; can be run with one call from an application; and allow user-declared variables,
conditional execution, and other powerful programming features.
115
MS-Access
Figure 113
Select the type of file and the name of file from which data is to be imported.
Click Import.
Depending on the type of the file from which data is to be imported, the further options
have to be chosen. For example, if data is imported from an Access database, following
window will appear as shown in Figure 114.
116
MS-Access
Figure 114
The various objects of the database are listed and the data desired from any of these
objects can be selected.
Click OK.
If it is an Excel file then a 6-step wizard will start which will ask for the following options:
Click Finish.
Similar steps with minor differences can be followed for other types of files. For example,
Microsoft Access, Dbase, Excel, Foxpro, HTML documents, Paradox, Text Files, Rich
Text Format, ODBC databases, Exchange.
Training Division, NIC, New Delhi
117
MS-Access
E Linking
In an Access database, linking data enables you to read and in most cases, update data
in the external data source without importing. The external data sources format is not
altered so that you can continue to use the file with the program that originally created
it, but you can add, delete, or edit its data by using Microsoft Access as well. You can
link a table only in an Access database, not in an Access project.
Microsoft Access uses different icons to represent linked tables, for example if Excel
sheet is linked then icon will be , under the Tables object tab and other tables that are
stored in the current database. If you delete the icon for a linked table, you delete the
link to the table, not the external table itself.
Linking is done by
Link dialogue box appears where file name and File type can be specified.
Click Link.
Note: The design of the table, thus linked, cannot be altered since it is linked with the
source.
118
MS-Access
E Assignments
I.
II.
119
MS-Access
120
Click on File>>Export.
Select file type as HTML and click Save.
View the new file through Internet Explorer or MS Word.
Repeat the above steps with a Query already created in database Employee.
MS-Access
3.
Office links
Figure 115
4.
VI
2.
Select the table / query from which you want to merge fields in a MS Word
document.
3.
From the office links dropdown list select the option Open MS Word
Document.
4.
Choose the option Create a new document / link your data to an existing
word document.
5.
In the MS Word window, type the matter, and insert fields from the special
Mail Merge window, which appears as shown in Figure 116.
6.
121
MS-Access
Figure 116
122
Annexures
MS-Access
q Annexure I
Various Data Types are given in the following table
Data Type
Text
Description
holds text up to 255 characters, including letters, numbers and special
characters.
Memo
holds text up to 65000 characters, is of variable length: you do not
specify a maximum size for it.
Number
holds numeric data.
Date/Time
holds date and time. You can enter Date/Time on the format you
select for the field.
Currency
holds number used as amounts of money.
AutoNumber
holds sequential numbers that Access automatically enters.
Yes/No
holds two values, defined as Yes/No, True/False or On/Off,
depending upon the format you give to it in the field properties
panel.
OLE Object
holds data from other Window application that support object linking
and embedding. This field can be used to attach pictures, Sound Files
or any other type of data available from Windows applications that
supports OLE.
Hyperlink
holds the address of an object, document or web page, which you
can display simply by clicking the field.
Lookup Wizard lets you create a lookup field where user chooses values from the
list of values entered or taken from the table.
A 1.1
MS-Access
q Annexure II
E Field Properties
Field properties can be changed by using the options on the General and Lookup tabs
in the field properties pane in the table design window. Different data types offer
different properties.
Note : The field properties area of the table design window shows only one field property
at a time. Make sure that the arrow symbol should appear before the selected field.
Field properties area is shown in Figure 117.
Figure 117
A 2.1
MS-Access
Field Size
FieldSize property is used to set the maximum size for data stored in a field set to the
Text, Number, or AutoNumber data type.
Settings:
Data Type
Text
AutoNumber
Number
Default Setting
50
Long Integer
Settings Allowed
Number from 0 to 255
Long Integer or
Replication Id
Long Integer
Byte
Decimal
Integer
Single
Double
Replication
Size
4 Byte
1 Byte
12 Byte
2 Byte
4 Byte
8 Byte
16 Byte
Note : Use the smallest possible FieldSize property setting because smaller data sizes
can be processed faster and require less memory.
Caution : If you convert a large FieldSize setting to a smaller fieldsize that already
contains data, you might lose data.
Format
Format property is to customize the way in which Numbers, Date, Time, and Text are
displayed and printed. For example, in a Price text box, its Format property is set to
Currency and its Decimal Places property to 2 or Auto. If you enter 4321.678 in the
control, the number would be displayed as $4,321.68.
A 2.2
MS-Access
The Format property provides different settings for different data types.
Meaning
Display spaces as literal characters.
Display anything inside quotation marks as literal characters.
Force left alignment instead of right alignment.
Fill available space with the next character.
Display the next character as a literal character. You can also display
literal characters by placing quotation marks around them.
Display the formatted data in the color specified between the brackets.
Available colors: Black, Blue, Green, Cyan, Red, Magenta, Yellow,
White.
Input Mask
InputMask property is used to make data entry easier and to control the values, users
can enter in a text box control. For example, an input mask for a Phone Number field
that shows, exactly how to enter a new number: (___) ___-____.
A 2.3
MS-Access
L
?
A
a
&
C
.,:;-/
<
>
!
Description
Digit (0 to 9, entry required, plus [+] and minus [] signs not allowed).
Digit or space (entry not required, plus and minus signs not allowed).
Digit or space (entry not required; spaces are displayed as blanks
while in Edit mode, but blanks are removed when data is saved; plus
and minus signs allowed).
Letter (A to Z, entry required).
Letter (A to Z, entry optional).
Letter or digit (entry required).
Letter or digit (entry optional).
Any character or a space (entry required).
Any character or a space (entry optional).
Decimal placeholder and thousand, date, and time separators. (The
actual character used depends on the settings in the Regional Settings
Properties dialog box in Windows Control Panel).
Causes all characters to be converted to lowercase.
Causes all characters to be converted to uppercase.
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. You can include the exclamation point anywhere in the input
mask.
Causes the character that follows to be displayed as the literal
character (for example, \A is displayed as just A).
Note : Setting the InputMask property to the word Password creates a passwordentry control. Any character typed in the control is stored as the character but is
displayed as an asterisk (*).
A 2.4
MS-Access
The following table shows some useful input masks and the type of values can be entered:
Input mask
(000) 000-0000
(999) 999-9999
(000) AAA-AAAA
#999
>L????L?000L0
>L0L 0L0
00000-9999
>L<??????????????
SSN 000-00-0000
>LL00000-0000
Sample values
(206) 555-0248
(206) 555-0248 or ( ) 555-0248
(206) 555-TELE
20 or 2000
GREENGR339M3 or MAY R 452B7
T2F 8M4
98115- or 98115-3007
Maria or Brendan
SSN 555-55-5555
DB51392-0493
Caption
Caption property provides helpful information to the user through captions on objects
in various views:
Field captions specify the text for labels attached to controls created by dragging a
field from the field list and serves as the column heading for the field in table or query
Datasheet view.
Form captions specify the text that appears in the title bar in Form view.
Report captions specify the title of the report in Print Preview.
For Example,
Field Name
Emp_code
Ename
Caption
Employee Code
Employee Name
A 2.5
MS-Access
Caption appeared as
column Heading in
Datasheet view
Figure 118
Note : Include two ampersands (&&) in the setting for a caption if you want to display
an ampersand itself in the caption text. For example, to display Save & Exit, type
Save && Exit in the Caption property box.
Default Value
DefaultValue property is to specify a value that is automatically entered in a field when
a new record is created. For example, in an Addresses table you can set the default
value for the City field to New York. When users add a record to the table, they can
either accept this value or enter the name of a different city.
Note :
The DefaultValue property doesnt apply to check box, option button, or toggle
button controls when they are in an option group. It does apply to the option
group itself.
A 2.6
MS-Access
The DefaultValue property applies to all table fields except those fields with the
data type of AutoNumber or OLE Object.
Value
Todays date
Current date and Time
Number zero
True
No
Letter CA
Data Type
Date/Time
Date/Time
Number or Currency
Yes/No
Yes/No
Text
The use of ValidationRule property is to specify requirements for data entered into a
record, field, or control. When data is entered that violates the ValidationRule setting,
ValidationText property can be used to specify the message to be displayed to the user.
Note: The ValidationRule and ValidationText properties dont apply to check
box, option button, or toggle button controls when they are in an option group.
They apply only to the option group itself.
A 2.7
MS-Access
ValidationText property
Entry must be a nonzero value.
Entry must be blank or greater than 1000.
Entry must be 5 characters and begin
with the letter A.
>= #1/1/96# And <#1/1/97#
Entry must be a date in 1996.
DLookup(CustomerID,
Entry must be a unique CustomerID
Customers, CustomerID = Forms! (domain aggregate functions are allowed
Customers!CustomerID) Is Null
only for form-level validation).
Note : If validation rule is set for a field, Microsoft Access doesnt normally allow
a Null value to be stored in the field. If you want to allow a Null value, add Is Null
to the validation rule, as in <> 8 Or Is Null and set Required property to NO.
A 2.8
Description
A zero-length string is a valid entry.
(Default) A zero-length string is an invalid entry.
MS-Access
Required Property
Required property is used to specify whether a value is required in a field. If this property
is set to Yes, then it is must to enter the value in that field.
Note: The Required property doesnt apply to AutoNumber fields.
Results from combined settings of the Required and AllowZeroLength properties are:
Required
No
No
Yes
Yes
Value stored
Null
Null
(not allowed)
Null
Null
Zero-length string
(not allowed)
(not allowed)
(not allowed)
(not allowed)
Zero-length string
Zero-length string
Indexed Property
Indexed property is used to set a single-field index. An index speeds up queries on the
indexed fields as well as sorting and grouping operations. For example, search for specific
employee names in a eName field of employee table, create an index for this field to
speed up the search for a specific name.
The Indexed property uses the following settings:
Setting
No
Yes (Duplicates OK)
Yes (No Duplicates)
Description
(Default) No index.
The index allows duplicates.
The index doesnt allow duplicates.
A 2.9
MS-Access
Remarks
Use the Indexed property to find and sort records by using a single field in a table. The
field can hold either unique or non-unique values. For example, an index on an Emp_code
field in an Employee table in which each emp_code is unique or create an index on a
eName field in which some names may be duplicates. If the primary key for a table is
a single field, Microsoft Access will automatically set the Indexed property for that
field to Yes (No Duplicates).
Note : Indexed property is not applicable to Memo, Hyperlink, or OLE Object data
type fields. Index can be created to any no. of fields in table. The indexes are created
when table is saved and are automatically updated when records are changed or
added. Indexed property can be added or deleted any time in table Design view.
Lookup Properties
To open lookup property sheet
Select field.
Figure 119
A 2.10
MS-Access
Figure 120
Description
This control is used to display the fields in Datasheet View (i.e.
set property to List Box or Combo Box for Lookup fields)
Row Source Type This control is used to choose the source of data in the fields(Table/
query, Value List or Field List).
Row Source
Lets you choose the source of the controls data. In the above
figure the row source is value typed.
Bound Column
This control is used to specify which column in the row source
contains the value to store in lookup fields. As shown in above
figure, the list box contains two columns but it will store the second
column value in designation field so bound column value is 2.
Column Count
This property specifies how many columns to display.
Column Heads
This property is used to choose whether to show column headings.
By default no column headings appear. To show column headings
change setting to Yes.
A 2.11
MS-Access
Column Widths
List Rows
List Width
Limit to List
A 2.12
MS-Access
q Annexure III
E Built-in drivers and ODBC drivers
Save As Type box in the Export Object Object Name To dialog box.
A 3.1
MS-Access
Figure 121
From the screen appeared in Figure 121, select the driver name. Click Add.
Figure 122
A 3.2
Specify the Data Source Name and select the database name by clicking on Select
button, as shown in Figure 122.
Click OK. Data Source Name will be listed in the ODBC database Administrator
which can be used later on.
Training Division, NIC, New Delhi
Notes
Notes
Getting Started
with
MS-Access
Government of India
Ministry of Communications & Information Technology
Department of Information Technology
National Informatics Centre
Training Division
New Delhi
Getting Started
with
MS-Access
Government of India
Ministry of Communications & Information Technology
Department of Information Technology
National Informatics Centre
Training Division
New Delhi
Contents
PART - I
q
Case Study
16
Starting MS Access
20
Relationships
31
How it works?
Creating New Relationships
Editing the Existing Relationship
Query
39
Simple Query
Performing Calculation in the Query
Using Criteria or Advanced Filters to retrieve certain Records
Parameter Queries
Action Queries
More about Queries
Accessing Query through Form
Forms
59
Reports
Creating a Report using Wizard
Creating a Report in Design View
Creating a Report for Mailing Labels
Creating Calculated fields in the Report
Sorting and Grouping Records
76
93
Annexures
...113
MS-Access
The steps/commands, the user has to perform, are preceded by the symbol .
For example : Switch on the Computer.
(ii)
(iii) The options/sub options to be selected or the messages given by the system,
appear in the Bold font;
For example : Select the File >> New option.
This means that first click on the File menu and then click on the sub option
New from its drop down menu.
(iv) The button to be selected appears in Bold font and the selection is through
clicking the mouse.
For example : Click the Cancel Button.
(v)