Msaccess
Msaccess
Microsoft Access stores data in its own format based on the Access Jet Database Engine. It can
also import or link directly to data stored in other applications and databases.[1]
Software developers, data architects and power users can use Microsoft Access to
develop application software. Like other Microsoft Office applications, Access is supported by Visual
Basic for Applications(VBA), an object-based programming language that can reference a variety of
objects including DAO (Data Access Objects), ActiveX Data Objects, and many other ActiveX
components. Visual objects used in forms and reports expose their methods and properties in the
VBA programming environment, and VBA code modules may declare and call Windows operating
system operations.
Use of Access
Most users of Microsoft Access use the tables, forms and queries. Database tables are very
similar to spreadsheets. After listing the subject matter of each column, the user has the option of
adding additional columns to detail the attributes of the subject. When done, each row has any
needed information about each subject. The form method of data entry available in Microsoft
Access allows one to enter information for the system in graphical form for it to be transferred to
a database. Some may find this easier for data entry if they do not have to finalize the tables. The
query function of Microsoft Access increases productivity by allowing the user to combine
information from more than one table and specify the conditions of the data that the user
retrieves. It shortens the time-consuming task of having to look manually through bountiful
information to pinpoint certain ones that have certain characteristics.
Tables. All data is stored in tables. When you create a new table, Access asks you
define fields (column headings), giving each a unique name, and telling Access the data
type. Use the "Text" type for most data, including numbers that don't need to be added e.g.
phone numbers or postal codes. Using Wizards, Access will walk you through the process of
creating common tables such as lists of names and addresses. Once you have defined a
table's structure, you can enter data. Each new row that you add to the table is called
a record. To define relationships between tables:
Queries. Use a query to find or operate on the data in your tables. With a query, you
can display the records that match certain criteria (e.g. all the members called
"Barry"), sort the data as you please (e.g. by Surname), and even combine data from
different tables. You can edit the data displayed in a query (in most cases), and the data in
the underlying table will change. Special queries can also be defined to make wholesale
changes to your data, e.g. delete all members whose subscriptions are 2 years overdue, or
set a "State" field to "WA" wherever postcode begins with 6.
Forms. These are screens for displaying data from and inputting data into your
tables. The basic form has an appearance similar to an index card: it shows only one record
at a time, with a different field on each line. If you want to control how the records
are sorted, define a query first, and then create a form based on the query. If you have
defined a one-to-many relationship between two tables, use the "Subform" Wizard to create
a form which contains another form. The subform will then display only the records
matching the one on the main form.
Reports. If forms are for input, then reports are for output. Anything you plan to
print deserves a report, whether it is a list of names and addresses, a financial summary for
a period, or a set of mailing labels. Again the Access Wizards walk you through the process
of defining reports.
Pages (Access 2000 - 2003). Use pages to enter or display data via Internet. Pages
are stored as HTML files, with data read from and written to the database. Michael Kaplan
has published a free utility to convert Access forms and reports into Data Access Pages.
(Pages were deprecated in Access 2007.)
Macros. An Access Macro is a script for doing some job. For example, to create a
button which opens a report, you could use a macro which fires off the "OpenReport" action.
Macros can also be used to set one field based on the value of another (the "SetValue"
action), to validate that certain conditions are met before a record saved (the
"CancelEvent" action) etc.
Modules. This is where you write your own functions and programs if you want to.
Everything that can be done in a macro can also be done in a module, but you don't get the
Macro interface that prompts you what is needed for each action. Modules are far more
powerful, and are essential if you plan to write code for amulti-user environment, since
macros cannot include error handling. Most serious Access users start out with macros to
get a feel for things, but end up using modules almost exclusively. On the other hand, if your
needs are simple, you may never need to delve into the depths of Access modules.
Creating table
First, choose to create a blank database rather than using any of the pre-built templates. Come back and
click on Create.
a default table, and setting it up ready to use. In our case though, we don’t want to do that. We want to
The best way to get there is to click on the X at the top right to close
the table, click the Create tab in the ribbon, and then click on Table
Design. If you get lost, close Access down without saving anything,
Here’s the thing to remember. You need to know what you want to do first, design the table to do that,
and then add the data. It’s cumbersome to change your mind afterwards.
Our main job here is to decide on the fields we want to store in the table, and what sorts of information we
want to store in each one. If you’re using my example, fill things out so they look like this.
Before we can move on from here, there’s one thing that can be a little complex, but you need to
understand. Access is a relational database. The relational part means that you can deal with multiple
One of the aims of relational databases is to minimise both repetition and wasted space. I’m not going to
go into the theory, but this is called normalisation. There are many other places to research the topic.
Notice that each of the classic sci-fi authors is mentioned a number of times in the spreadsheet. To
achieve the same thing in Access, we create another table especially for the authors, and then relate the
new table. That way each author only exists once, and the opportunity for errors is greatly reduced.
For the moment, accept my request that you create the author field as a Number.
Save the table. The quickest way is to click on the Save button in the toolbar. That might not be the
simple option. Another note. The table names are not file
workbook.
But”¦ before Access will let you save the table, there’s another thing you need to do. Just take my word for
this one. In almost every case, a table in Access needs to have a field somewhere in it that is guaranteed
to have a different value on every row. I mean every row, so you couldn’t make use of the Pages field for
instance, because eventually you’d be bound to end up with two books with the same number of pages.
The easiest way to do this is to add another field just for the job. That’s normally referred to as
the ID field.
So, click Yes on the crazy dialog box which is too wide to show effectively in the post”¦
row that you add to the table. Don’t worry about it. It just happens.
Now go ahead and save the table again, and close it. When you’ve done that, run through the process
again to create an Author table that looks like this. Same deal with the ID field. Just let it be created.
Before we can start using the tables, we need torelate them to each
other.
theRelationships button.
Add both of the tables using the Show Tables dialog.
Close the dialog when you’ve finished, and take a break for a moment. Let me explain.
Tables in Access generally relate in special ways. The most common of these is what is called a many to
one relationship.
In our case, for each author there can be many books. To create this relationship, click on ID in
the Author table, and drag it to the Author field in the Book table.
Access asks you for some details for the relationship. The only change you need to make is to tick
Another thing that helps make it easier to use the Book table. What actually gets saved in the Author field
is the ID of the author from the Author table, but that’s a bit difficult to make use of, because you’d have to
go and look up the other table to check on the correct value. So we’re
going to set things up so that it looks up the author name all by itself.
Open the Book table again by double-clicking on its name. Click the Design button. Click on
theAuthor field, and then on the Lookup tab down below the field list.
Fill out the fields as noted. You’re going to need a more in-depth tutorial to explore the reasons for the
Move to the Author field, and you’ll see a combo box appear. Click the arrow, and you’ll see a list of
authors. Click the correct one, and move on. Go ahead and fill out the rest of the records.
Data types
Data types
Think of a field's data type as a set of qualities that applies to all the values contained in the
field and that determines what kind of data those values can be. For example, values that
are stored in a Text field can contain only letters, numbers, and a limited set of punctuation
characters. In addition, a Text field can contain a maximum of 255 characters.
TIP: Have you ever wanted to add a calculated field to a table? In Access 2010, you can.
Attachment Files, such as digital photos. Multiple files can be attached per record. This
data type is not available in earlier versions of Access.
AutoNumber Numbers that are automatically generated for each record.
Currency Monetary values.
Date/Time Dates and times.
Hyperlink Hyperlinks, such as e-mail addresses.
Memo Long blocks of text and text that use text formatting. A typical use of a Memo field
would be a detailed product description.
Number Numeric values, such as distances. Note that there is a separate data type for
currency.
OLE Object OLE objects, such as Word documents.
Text Short, alphanumeric values, such as a last name or a street address.
Yes/No Boolean values.
Create form
Creating reports
Do some more next than choose design and finally get.
What is a macro?
A macro is a tool that allows you to automate tasks and add functionality to your forms, reports,
and controls. For example, if you add a command button to a form, you associate the
button's OnClick event to a macro, and the macro contains the commands that you want the
button to perform each time it is clicked.
In Access, it is helpful to think of macros as a simplified programming language that you write
by building a list of actions to perform. When you build a macro, you select each action from a
drop-down list and then fill in the required information for each action. Macros enable you to
add functionality to forms, reports, and controls without writing code in a Visual Basic for
Applications (VBA) module. Macros provide a subset of the commands that are available in
VBA, and most people find it easier to build a macro than to write VBA code.
For example, suppose that you want to start a report directly from one of your data entry forms.
You can add a button to your form and then create a macro that starts the report. The macro can
either be a standalone macro (a separate object in the database), which is then bound to
the OnClick event of the button, or the macro can be embedded directly into the OnClickevent of
the button itself — a new feature in Office Access 2007. Either way, when you click the button,
the macro runs and starts the report.
You create a macro by using the Macro Builder, which is shown in the following illustration.
To display the macro builder:
On the Create tab, in the Other group, click Macro. If this command is unavailable, click the arrow
beneath either theModule or the Class Module button, and then click Macro.
Understand macros
The term macro is often used to refer to standalone macro objects (that is, the objects that you
see under Macros in the Navigation Pane), but in reality, one macro object can contain multiple
macros. In that case, it is referred to as a macro group. A macro group is displayed in the
Navigation Pane as a single macro object, but a macro group actually contains more than one
macro. Of course, it is possible to create each macro in a separate macro object, but often it
makes sense to group several related macros into a single macro object. The name in the Macro
Name column identifies each macro.
A macro consists of individual macro actions. Most actions require one or more arguments. In
addition, you can assign names to each macro in a macro group, and you can add conditions to
control how each action is run. The following sections discuss each of these features in more
detail.
Macro names
If your macro object contains only one macro, macro names are unnecessary. You can just refer
to the macro by the name of the macro object. However, in the case of a macro group, you must
assign a unique name to each macro. If the Macro Namecolumn is not visible in the Macro
Builder, click Macro Names in the Show/Hide group on the Design tab. More information
about running macros in macro groups appears later in this article.
Arguments
An argument is a value that provides information to the action, such as what string to display in a
message box, which control to operate on, and so on. Some arguments are required, and some
others are optional. Arguments are visible in the Action Arguments pane at the bottom of the
Macro Builder.
Creating relationship
elect a field name from one table by holding down the left
mouse button.
Drag the field name from one table to the other table in the
desired relationship.
Drop the first field name onto the field name you want to
relate by releasing the left mouse button.
In the example above, we selected the Book ID field from
the Books table and dragged and dropped it on the Book
ID field in the Orders table.
The Edit Relationships dialog box appears.
One-to-One
One-to-Many
Many-to-Many
The relationship type you will come across most frequently—and the one
created in our bookstore scenario—is theOne-to-Many relationship.
One-to-Many
The One-to-Many relationship means data for that field will show up a
single time in one table but many times in the related table.
For example, let's look at one of the book titles in our bookstore. The Book
ID for the book should appear only once in the Books table because this
table lists every title stocked in the store. But it will probably appear many
times in the Orders table because we hope it gets ordered by many people
many times.
You should click Enforce Referential Integrity to make sure you never
have an order for a book that doesn't appear in the Books table. Selecting
this option tells Access to check for these things when someone is working
with your data records.
When the Switchboard Manager window appears, click on the Edit button.
Next, you will need to add buttons to the switchboard. To do this, click on the New
button.
Enter the text that will appear next to the button. Select the command. In this example,
we've set up a switchboard item to open the form called frmSuppliers. Click on the OK
button.
Now, when you open your Access database, the switchboard should open automatically
and display any buttons that you've configured.