Database Tips

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

DATAB GENER

ASE
Field size reduction reduces storage space on AL
TIPS
a database file. Field Characteristics
Fields should be set to appropriate lengths for < in format makes it type all lower case
each entry. >In format makes it type all upper case

Field Properties - When creating fields in a table, each field will need
to be assigned a data type also known as field properties or field
characteristics. The list opposite are all the available data types.
We can then further format our fields using the general and lookup
tabs below the fields list.

A Default Value is a value that is automatically entered into a particular field of every new record. When
records are added, the default value can either be accepted or changed.
A Mandatory field is a field which must be completed for every record and can be set by setting
Validation
Required Rules are used to set the requirements of the text
to Yes.
that the user enters into a particular field. It defines the only
permitted entries that the user may make. If text is entered
which breaks the validation rule, a message displaying some
pre-set Validation Text will be displayed.
Input Masks control how
Mask Used for data is entered and
character displayed in a field. The
0 Number – entry required Input Mask field property
9 Number – entry not required in Design View is used. A
# Number, + or -, or space – entry not required combination of different
L Letter – entry required symbols are entered, which
? Letter – entry not required define the way in which
A Letter or Number – entry required
data in that field is expected
A Letter or Number – entry not required
to be entered, and how it
& Any character or space – entry required
will be shown.
C Any character or space – entry not required
., Decimal point and thousands separator
:/ Date and time separators
< Converts characters to the right to lowercase
> Converts characters to the left to uppercase
! Mask fills from right to left
\ Makes the character that follows to be displayed as itself,
e.g. \9 will be displayed as 9

Lookup Field - When creating a table, a


field can be defined that already contains

RELATI
all the possible values that can be entered.
This is called a Lookup Field and will
speed up data input and reduce typing

ONSHI
mistakes, because at data entry time there
Primary Key – applied to unique data in a Use of a primaryis no need
key to enter
prevents any values,
duplication ofmerely
select an entry from the presented list.

REPOR
field, i.e. student number, barcode or product records in a table that allows sorting and
The field can also be set so that only

PS
number. If there is no valid field to use then querying to be carried out more efficiently.
we generally use Autonumber which will those key
Setting a primary entries
willinallow
the Lookup
linking field list will
of tables
automatically start at 1 for the first record and called Relationships. The be accepted.
General section will

TS
then 2 etc. for each record added. also show the Index property to be set to Yes (No
Information within a report can be grouped, so that recordsDuplicates).
which contain the same information in a
particular field, can appear grouped together on the report. Sorts can also be applied within the groups.

Once tables are designed and primary Relationships are usually applied between tables, which
keys applied, a Relationship may be contain a common field. Usually the related field in the
applied between
Page breaks cantwo or more
be forced intables
any to first table is the
Calculated primary
fields can bekey field and
manually is known
created as the to
on reports
link them
section of together.
a report byOnce two clicking
double or more Primary
obtain anyTable. In this way, a record
mathematical/statistical in one table
information thatcan link
may
tables are linked by a relationship,
the appropriate section and setting the the tobefurther
required. Calculations using expressions like Sum in
information in another table. The related field
data from all of the tables may
required ForceNewPage property. be used theand
second
Counttable
willishave
known as Foreign
different effectsKey. Applying
depending on
to create a single query, form or report. relationships
which level that are added to in the report. be linked
allows many smaller tables to
together to form the complete database, improving its
overall efficiency.

Subdatasheets are used in Datasheet View to display the contents of a related table on the same sheet. Each
record in the main data sheet view can be expanded to show the related records from the subsidiary table in a
second view called a Subdatasheet. Records Typesinofsub
Relationships
datasheets can also be added to or edited in this view.
Calculated fields can be used to show Data fields can be added to report headers
One-to-Many – This
Entering new datameans
into athat one record isfrom
Subdatasheet one the
exactly table canas
same have manydata
entering related records
directly intointheanother table.
main table.
percentages in reports. In particular they and/or footers. These can include fields from
i.e. one car may have many jobs. The fact that one of the fields in the link is a primary key and the other is
can show the value of each detail line as a the field list or the date and time. Page
not, defines
Think theCustomer
of the relationship
tableasinOne-to-Many.
the Deli database which displayed the orders against the + and then clicked on
percentage of the report total. numbers can be added to page headers or
One-to-One – is used where one record in onethe
showed table is linked
orders to customer.
for that only one record in another, This can be used
footers.
to split a table with many fields or if part of a table is removed for security reasons or if the second table
contains optional data.
Many-to-Many is used when a record in the first table can have many matching records in the second, and
vice versa. E.g. a single product may have many orders and a single order may be for many products. A
single Many-to-Many relationship cannot exist. An intermediate junction table must be created with One-
to-Many links to the two original tables. It must contain two fields: the foreign keys from both tables.
It is possible to import data from one database to another or from a different type of file such as spreadsheet
or text file. This can be very useful if the data required for an Access application already exists in another
location, either in a different database or in Excel spreadsheet for example. Importing converts the source data
into the format of the destination application i.e. Access. The data can be then edited as if it had been created
in Access. This allows much greater flexibility for data entry.

As well as importing data into Access, data can be exported from Access into another format.

Linking data involves creating a database table from an external source without creating a separate copy of
the object. Changes to the source file are automatically reflected in the database. Changes can be made using
the database and these are made directly to the source file. The disadvantage is that if the source file is ever
moved or deleted, the database table will no longer be available.

QUERI
ES
Wildcards – when looking for information including the word sales, which could also include sales manager,
sales assistant, sales supervisor etc.
? represents 1 character and * represents a number of characters

Various summary calculations can be


carried out on numerical data within
Access. Clicking on the Totals icon in
the Design tab when using a query will
allow you to select from the list.

Criteria null gives blank field results. Useful to ensure all entries are completed fully.

Top Values - Return option icon in query setup section can view top 10 or percentages.

Calculated fields allow you to perform calculations e.g.


Total Amount: [Amount]*[Price]

Parameter queries allow you to set up queries where you need an entry requirement to run the query, e.g.
criteria example [Enter Town Required] or
Like [Enter Letter Required]&* or >=[from lower value] and <=[to upper value]
An Append query selects a group of records from one table using all the features of query, and adds them to
the end of another table. Note that the information is not removed from the original table.

A Delete Query will delete a selected group of records from one or more tables. This could be run after an
Append query for example, to remove all the updated records from the original table.

A Make-Table Query selects data from one or more tables, using all the features of a query, and creates a
new
Antable fromQuery
Update that data.
will Not all the
update fields from
a specific fieldthe original
within table(s)For
a table(s). need to be included
example, in the
increasing new table.
all prices by 10%,
changing a name of a product, etc.

A Find Duplicate Query will search a table for records where individual fields have duplicate values. For
example, company details that may have been entered twice by mistake.
By default a line on a query result represents a record of some kind. A Crosstab Query however shows
summarised values such as Sum, Avg, Count, Max, Min, etc, for fields within a table or query and groups
them together into a matrix type of display. The columns and rows of the matrix can be any fields from the
table or query. Crosstab queries can either be created via the wizard or manually. It is recommended to
use the wizard.

The Find Unmatched Query will find records in one table that do not have matching records in another
table. For example, Customers who do not have any records on an Orders table or Students with no records
on a Courses table.

FORMS
Just as a subdatasheet can be contained A Main/Subform can be created from two
within a datasheet, a subform, containing existing forms without using the Form
specific, linked information, can be Wizard. Create both forms in the normal
contained on a main form. The best was to way. Choose one as the main form, and use
achieve this is using the Form Wizard. the Subform/Subreport button to add the
other as a subform.
Instead of creating a form with a subform within it,
it is possible to create two forms which are separate, Single forms can be created using
but which link together. The main form will be fields from different tables. To do
viewed and when a record is chosen, a button can this, a query must be created which
be pressed which will open up the linked form contains all the fields that are
where the relevant related data will be displayed. required on the form. This query
This is useful when the main form contains a large then acts as the basis for the form,
amount of information, and the addition of a which is created in the usual manner.
subform would clutter the screen.

There are different types of form controls: bound A text box is drawn on a form, and the
A (gets
Combo Box from
its data is a field on a form,unbound
a source/field) which will(not
allow a value to be expression
chosen from a dropinto
entered down list or
it. The will search
expression may
forlinked
a record
to a that
data matches a value
source) and that is entered
calculated. A into the combo box. This any
include willof
speed up data
the usual entry and will
mathematical symbols
stop incorrectfield
calculated data uses
entry,a mathematical
such as spelling mistakes to
expression etc. (+ - * /) and expressions such as Average,
obtain its information. These fields are calculated Sum, Max and Min. When the form is
There
usingare three
other options to from
information choosethefrom, whenand
database using
are the wizard to create
viewed,thethe
form:
field will calculate the expression,
calculated each time they are required. and will recalculate as the record changes.
I want the combo box to look up the values in a table or query - Will display in the combo box, all the
values already in a specified field in a named table, even when there are duplicate values. There will be one
value for each record.

I will type in the values that I want - Allows the user to type in the values they want to display in the combo
box. This will prevent duplications appearing in the combo box and in the event of creating a form, before
data has been entered in a table, will allow only specific information be entered into the field.

Find a record on my form based on the value I selected in my combo An easy


box way to allow
- Will defineaavalue
command button is
to be entered
A Command Button is a button on a form which, to use the Command Button Wizard which
into the combo box, will then search for a record that matches the entry. It is advisable to use a field unique to
when pressed, performs an action that the user has takes the user through the steps of creating a
each record, such as a Works Number.
defined previously, such as closing forms, opening button.
reports, printing etc.

As well as entering data, the value selected in a combo box can be used to find complete records from a table.
When creating these combo boxes, it is better to include the Primary Key as the field in the combo box, as
this is a unique field in the table and each value will successfully locate a single record.

List Boxes are very similar to Combo boxes except the options are permanently viewed in a list format,
without having to click a drop down arrow. The amount of values which appear in the box depends on the size
of the list box you create. If the list box is too small, scroll bars will appear to the side of the list box, to allow
you to scroll through the values.

Check boxes can also be added to forms Option groups allow a selection to be made on a form,
when a Yes/No answer is required. where more than one option is available. Only one
option can be chosen.
A Tab Control can be used to split the form into two or more pages. This is useful if a lot of fields are needed
on one form, especially if the fields can be easily divided into separate categories.

Data fields can be added to form headers and/or footers. These can include fields from the field list or the
date and time. Page numbers can be added to headers or footers that will automatically create page
header/footer areas and will only be seen when forms are printed.

MACR
OS
A macro is another object in Access. It consists of a single action or multiple actions, sometimes with Action
Arguments, which set the controls for the action e.g. the Action Arguments for the OpenReport action will
contain details of which report is to be opened, what view will be used, or if a filter/query or condition which
restricts the records for the report to be used. Once created, a macro can be run manually or more
commonly, attached to a control.

Action Explanation Action Explanation


Add/Menu Add menu to menu bar Apply Filter Applies Filter/Query to specified
data
Beep Make computer beep CancelEvent Cancels event that macro is
attached to
Close Close an object CopyObject Copy an object
DeleteObject Delete an object Echo Show following macro actions
screen
FindNext Find next record for FindRecord Find a specific record for specified
specified criteria criteria
GoToControl Move the cursor to a control GoToPage Move to specific page
GoToRecord Move to specific record Hourglass Show the hourglass
Maximize Maximise current window Minimize Minimize current window
MoveSize Move/resize active window MsgBox Show message box
OpenData Open a data Access page OpenDiagram Open a schema
AccessPage
OpenForm Open a form OpenModule Open a module
OpenQuery Open a query OpenReport Open a report
OpenStored Open a stored procedure OpenTable Open a table
Procedure
OpenView Open a datasheet view OutputTo Create a file to export data into
Quit Quit Access Rename Rename an object
Repaint Object Update screen activity Requery Requery an object
Restore Makes active window RunApp Run/Open an application
original size
RunCode Run a Visual Basic Module RunCommand Carry out a menu command
RunMacro Run a macro RunSQL Run Standard Query Language
Save Save current object SelectObject Select an object
SendKeys Process the following key SendObject Send the specified object via e-
presses mail
SetMenuItem Set status of customised SetValue Set a value for a specified control
menus etc
SetWarnings Show Access warning dialog ShowAllRecords Display all records
boxes
ShowToolbar Show specified toolbar StopAllMacros Stop all currently running macros
StopMarco Stop currently running TransferDatabase Import/link data from another
macro database
TransferSpreadsheet Import/link data from a TransferText Import/link data from a text file
spreadsheet

Macros are easily created and this usually involves selecting an Action or Actions and specifying Action
Arguments to control the operation of each action. For example, an Open Form macro can be created to
open a specified form. Action Arguments must be set up to state which form to be opened and if the form is
to be viewed in Form, Design or Datasheet View. Other Action Arguments can be used to set controls for
the form, such as whether data can be added, edited or whether the form is to be read-only.

Once a macro has been created it can be attached to various controls on a form, such as a data field, image,
command button or an option group. It can also be attached to the whole form.

When it has been attached, an Event needs to be set up in the properties of the control. This defines what will
cause the macro to run e.g. on a single or double click of the mouse, or when the field is updated or when the
form is opened. The possible events will vary with the type of control.

Instead of creating the macro then attaching it to the control, it is possible to create the macro as the control
itself is being added to the form. The Find macro, uses the Find and Replace function to search for records
using the field specified in the Action Argument for the command.

A common Multiple Action Macro opens one form and at the same time closes another. To create this,
simply place each action on a separate line, directly below each other, when creating the macro.

A macro that is saved with the name AutoExec will automatically run the macro actions as soon as the
database is opened. This is usually so that when a database is opened, a specific form is opened and
displayed rather than opening the database window.

You might also like