Make your own free website on Tripod.com

Introduction to Microsoft Access

 

 

 

Microsoft Access Launching

 

 

Introduction

 

Microsoft Access is a computer application used to create and manage computer-based databases on desktop computers and/or on connected computers (a network). Microsoft Access can be used for personal information management (PIM), in a small business to organize and manage all data, or in an enterprise to communicate with servers.

Like any other computer application, in order to use Microsoft Access, you must first open it. There are various ways this can be done. Microsoft Access is a classic computer application and it gets launched like the usual products you have probably been using. As such, to start this program, you could click Start -> (All) Programs -> Microsoft Access:

Windows Server 2003 Menu

As a regular member of the Microsoft Office suite of applications, if your installation created a sub-menu on the Start menu, you could click Start -> New Office Application and proceed from the New dialog box.

Although Microsoft Office 97 and Microsoft Office 2000 get installed in the C:\Program Files\Microsoft Office folder, they treat the shortcuts that launch them differently. The applications that are part of Microsoft Office 97 designate their shortcuts with full names and these are installed in the Microsoft Office folder. Microsoft Office 2000 (Premium) uses shortcut names to designate its shortcuts and they are installed in the Microsoft Office\Office folder. This means that you could launch an application from Windows Explorer or My Computer. Therefore, in order to launch Microsoft Access, locate its shortcut in Windows Explorer or My Computer and double-click it:

If you have a Microsoft Access database such as an E-Mail attachment, a file on a floppy disk, on the network, or in any other means, once you see its icon, you can double-click it. Not only will this action launch Microsoft Access, but also it will open the file.

You can also launch Microsoft Access from a shortcut. If you happen to use the software on a regular basis, you can create a shortcut on your desktop or on the Quick Launch area. Many users also take advantage of the Microsoft Office Shortcut Bar. Sometimes, the icon you need will not be there; in that case you should insert it manually.

If you are working on a network of related computers, your database may be located in another computer. In this case the network or database administrator would create a link or shortcut to the drive that is hosting the database. You can then click or double-click this link or shortcut to open the database and, as a result, launch Microsoft Access.

Keys to open Microsoft Access

 

Microsoft Access Shortcuts

 

 

Whenever you find out that you are using a particular program or file most regularly, you should have an icon on the desktop that can lead you to it quickly. This icon is called a shortcut. There are various techniques used to create a shortcut. Probably the first thing you should find out is where your application is located. You can find out by doing a search on the computer. Except on Microsoft Windows 95, you can create a shortcut from the Programs menu.

 

By default, the shortcuts on the Microsoft Office 97 applications are located in the C:\Program Files\Microsoft Office folder. And these shortcuts hold the same names as their respective programs; those will be Microsoft Word, Microsoft Excel, Microsoft PowerPoint, etc. The shortcuts of the Microsoft Office 2000 applications are located in the C:\Program Files\Microsoft Office\Office folder. These shortcuts use another naming convention. They are Msaccess, Winword, Excel, or Frontpg, just to name a few.

To create a shortcut from Windows Explorer or My Computer, you can right-click the icon or the shortcut of the application, position your mouse on Send To, and click Desktop (Create Shortcut).

To create a shortcut from the Start menu, click Start -> (All) Programs. When the program appears, you can right-click it, position the mouse pointer on Send To and click Desktop (Create Shortcut). 

 

Practical Learning: Creating a Shortcut 

 

 

  1. Right-click on an empty area of the Desktop ->  New -> Shortcut
     
  2. On the first page of the wizard, click the Browse button
  3. Make sure the Look In combo box is displaying the C: drive
  4. Double-click Program Files
  5. Double-click Microsoft Office
  6. If you are using Microsoft Access 97, click Microsoft Access. If you are using Microsoft Access 2000, double-click Office. Then click Msaccess:
     
  7. Click Open
  8. Click Next
     
  9. If you are using Microsoft Access 97, notice the name of the shortcut
    If you are using Microsoft Access 2000 or later, change the name of the shortcut to Microsoft Access:
     
  10. Click Finish

 

Microsoft Access Interface

 

 

 

Introduction

 

To get better acquainted with the user interface of Microsoft Access, we will use this section as a Practical Learning exercise.

The Title Bar

 

  1. As a regular Windows application, Microsoft Access shares some characteristics that are common to other programs. The top section of the interface is made of wide bar called the title bar:



    The left section of the title bar displays a small picture known as the system icon. This icon is used to identify the application. The icon holds a list of actions you can perform to close, minimize, maximize, move or restore the application. To perform any of these actions, you would click the system icon. This would display its list:



    This list can also be referred to as the system menu. To use one of its items, you can click it.

    To experiment with the system menu, click the system icon. If the Restore item is available, click it first
  2. Click the system icon again and click Move. Notice that the mouse pointer changes its shape into a cross
  3. Press and hold Shift (with your left hand). Then press the right arrow key (with your right hand) three times and press the down arrow key twice. Notice that the Microsoft Access window moves by units
  4. To move the window slowly, press and hold Ctrl(with your left hand). Then press and hold the left arrow key (with your right hand) while you are still holding Ctrl. Notice that these last two times, the window moves slowly
  5. To keep the window in its new position, press Enter
  6. The main area of a title bar is a long bar actually referred to as the title bar. This section is also used to perform the same operations available on the system menu. There are other operations you can perform different than the system menu depending on the way you click the main area of the title bar.
    To see an example, double-click the title bar. Notice that this maximizes Microsoft Access.
    The right section of the title bar displays three small squares referred to as the system buttons. They are used to minimize, maximize, restore or close Microsoft Access. These items are

 

 

Button

Role

Minimizes the window

Maximizes the window

Restores the window

Close - Windows XP

Closes the window

 

The Main Menu

 

 

  1. Under the title bar, there is a horizontal list of words. This list is made of items such as File, Edit, View, etc. Since there are various kinds of menus on this application, the menu on top will be referred to as the Main Menu and sometimes the Menu Bar.
    To use a menu item, you click one of its words and the menu expands. If an item is missing from the main menu, you can customize it.
    To experiment with the main menu, click File. There are four main types of menus you will encounter.
    When clicked, the behavior of a menu that stands alone depends on the actions prior to clicking it. Under the File menu, examples are Close or Exit
  2. A menu that is disabled is not accessible at the moment. This kind of menu depends on another action or the availability of something else.
    To see an example, one the main menu, double-click Window:
  3. A menu with three dots means that an intermediary action is required in order to apply its assignment. Usually, this menu would call a dialog box where the user would have to make a decision.
    As an example, on the main menu, position the mouse on File and click Open...
  4. On the dialog box, click Cancel
  5. A menu with an arrow holds a list of menu items under it. A menu under another menu is called a submenu. To use such a menu, you would position the mouse on it to display its submenu.
    For example, on the main menu, click Tools and position the mouse on Database Utilities
     
  6. To dismiss the menu, click Tools
  7. Notice that, on the main menu (and any menu), there is one letter underlined on each word. Examples are F in File, E in Edit, V in View, etc. The underlined letter is called an access key (the word access has nothing to do with Microsoft Access, it is used in this sense throughout Microsoft Windows and other operating systems). The access key allows you to access the same menu item using the keyboard. In order to use an access key, the menu should have focus first. The menu is given focus by pressing either the Alt or the F10 keys.
    To see an example, press Alt
  8. Notice that one of the items on the menu, namely File, has its borders raised. This means that the File menu item has focus
  9. Press t and notice that the Tools menu is expanded
  10. When the menu has focus and you want to dismiss it, you can press Esc.
    For example, press Esc
  11. Notice that the Tools menu has collapsed but the main menu still has focus
  12. Press f then press o. Notice that the Open dialog box displays.
  13. To dismiss the Open dialog box, click Cancel
  14. On some menu items, there is a key or a combination of keys we call a shortcut. This key or this combination allows you to perform the same action on that menu using the keyboard.
    If the shortcut is made of one key only, you can just press it. If the shortcut is made of two keys, press and hold the first one, while you are holding the first, press the second key once and release the first key. Some shortcuts are a combination of three keys.
    To apply an example, press and hold Ctrl, then press o, and release Ctrl
  15. Notice that the Open dialog box opens. To dismiss it, Click Cancel

 

 

From now on, in this book,

Press

Means

T

Press the T key

Alt, G

Press and release Alt. Then press G

Ctrl + H

Press and hold Ctrl. While you are still holding Ctrl, press H once. Then release Ctrl

Ctrl + Shift + E

Press and hold Ctrl. Then press and hold Shift. Then press E once. Release Ctrl and Shift

 

The Toolbars

 

 

Under the menu bar, there is another bar made of various buttons. This is called a toolbar. The toolbars change a lot in Microsoft Access. As you spend more time with this application you will learn how to recognize these toolbars. Each toolbar has a proper name and we will learn how to recognize them.

At times, there will be many toolbars that come and go while you are using Microsoft Access. For this reason, we will refer to each toolbar by its name. To know the name of a toolbar, you can right-click any word on the menu bar or any button on the toolbar. If you have only one toolbar on your screen, its name will have a check box. The other name(s) on the context menu is (are) the one (those) you can add to the screen if you wish:

You could also create your own toolbar.

 

The Status Bar

 

 

The status bar is a long horizontal bar that spans the whole button section of Microsoft Access. It will be used to provide some assistance or information about an item that is displaying or being accessed in Microsoft Access. At this time, it may be displaying Ready (and it means it)

 

Microsoft Access Database File

 

 

 

The Database as a File

 

A Microsoft Access database is primarily a Windows file like any other. It must have a location, also called a path, which indicates how the file can be retrieved and made available. Although you can create a database on the root directory such as the C: drive, it is usually a good idea to create your files, including your databases, in an easily recognizable folder.

Starting with Microsoft Windows 95 but except Windows NT 4.0, the operating system creates a folder called My Documents that provides a convenient place for a user to create files. With Windows 2000, XP, and 2003, there is also a My Documents folder but because various people may use the same computer, there is a different My Documents folder for each user. When a user logs in, the operating system locates his or her corresponding My Documents folder and makes it available. Throughout this site, we will use a folder called Exercises and located in a parent folder called Microsoft Access Desktop Databases.

Practical Learning: Creating a Folder

 

  1. As you probably know already, there are various ways you can create a folder. After installing the exercises, open Windows Explorer or My Computer and, on the left frame, select the folder that contains our lessons
  2. Create a folder named Exercises

From now on, throughout this site, we will consider that you have access to a folder named Exercises. All of the databases created in our lessons will be assumed to be located in that folder. If you are using another folder, throughout our lessons, remember to make the changes.

 

Creating a Database

 

Throughout this site, we will learn different techniques of creating a database. For now, a database is first of all a Windows file. It is mainly created from Microsoft Access. If you are just starting Microsoft Access, you can use one of the two top radio buttons. If Microsoft Access is already opened, to create a database, you can display the New dialog box and select an option from the icons on the property pages. Like every file in the computer, a database must have a name that identifies it. This name must be specified when creating the database.

 

Practical Learning: Creating a Sample Database

 

  1. To create a new database, on the main menu, click File -> New…
  2. In the New dialog box, click the Databases tab. Click Asset Tracking and click OK
  3. Locate the Exercises folder that will contain your databases and display it in the Save In combo box
     
  4. Click Create
  5. When the Database Wizard dialog box comes up, click Finish

 

Opening a Database

 

Unlike some other programming environments, Microsoft Access considers a database as a single Windows file with a name. We will eventually learn that this file can contain various objects that actually make up a database. Therefore, a Microsoft Access database is opened as a normal file.

To open a database, if you are just starting Microsoft Access, from the Microsoft Access dialog box, you can click the bottom radio button, Open An Existing File, locate the folder that contains the database, select the database file and click Open.

If you locate a database in Windows Explorer, My Computer, My Documents, or any other window that displays the Microsoft Access file icon, you can just double-click the icon and open the database. If you received a database as an email attachment, you can also open the attachment and consequently open the database file.

 

Microsoft Access keeps a list of most recently used databases under the File menu. In Microsoft Access 97, the list is limited to 4. In versions of Microsoft Access after 97, you can increase the list of MRU (most recently used) files in the General tab of the Options dialog box. To open a file that was previously used, you can click File from the main menu and click the database file from the list.

 

Practical Learning: Opening a Database

 

 

  1. Open Windows Explorer or My Computer and locate the folder that contains the resources that accompany our lessons. Copy a folder called GSC and paste it in your Exercises folder
  2. In Microsoft Access, to open a database, on the main menu, click File -> Open…
  3. Locate your Exercises folder and display it in the Look In combo box. Then double-click the GSC folder to open
  4. Click Grier Summer Camp
     
  5. Click Open

 

Overview of Database Objects

 

 

 

The Database Window

 

After creating or opening a database, unless the product is setup otherwise, the first object that appears is a rectangular box named the Database window. It is different on Microsoft Access 97 and Microsoft Access 2000 (and later versions).

The Database window is a classic object of Windows applications. It is equipped with a system icon on the left side of its title bar and three system buttons on the right side. Based on this, you can maximize, minimize, restore, or close it. You can also resize it by dragging one of its borders or corners. Because the Database window holds all objects that are part of a database, if you close the Database window, it also closes the database but leaves Microsoft Access opened. Because Microsoft Access is a Multiple Document Interface (MDI) application, if you maximize any of its child objects, such as the Database windows, the other objects that you subsequently open would be maximized also. In all versions of Microsoft Access, objects are organized in categories.

In Microsoft Access 97, each category is represented by a property page. Therefore, to select a category, you can click its tab.

Once in the property page of a category, to open an object:

  • You can double-click it
  • You can click it to select it, then click the Open button on the right side
  • You can also right-click an object and click Open

One of the biggest changes that Microsoft Access 2000 brought was on the Database window. It got completely redesigned and highly improved. Like all classic windows, it is equipped with a title bar similar to the Database window of the 97 version as we described above. Under the title bar, the Database window is equipped with a contextual toolbar. This means that the toolbar responds according to the object that is selected in the Database window.

Like all releases, objects in Microsoft Access are organized in categories. In the 2000 and later versions, objects are represented by the Objects Bar. Therefore, to select a category, you can click its button. Besides the buttons that represent categories, when you click a button, one, two, or three links allow you to create objects of that category. For example, you can create a table by double-clicking the Create Table By Using Wizard link.

 

 

To open an object:

  • Double-click it
  • Click it to select it and click the Open button on the Database window’s toolbar
  • Right-click it and click Open

Besides providing the ability to create a new object or open an existing one, you can also delete an object using the Database window’s toolbar. To do this, you can click the object to select it. Then, on this toolbar, click the Delete button. The Database window’s toolbar also provides four view buttons that allow you to change the way the list displays in the right side of the view. If you have used Windows Explorer, My Computer, or My Documents, you are probably familiar with these buttons. For example, here is the Database window that displays its list in Large Icons:

 

 

Database Objects: Tables

 

 

A Microsoft Access database is a file made of various internal objects: tables, queries, forms, reports, etc. All these are managed from an object called the Database Window. The objects are kept in categories. To access an object, you click the button that corresponds to its category.

A table is the central point of a database, because all data is stored in tables. For better organization, you will have various tables in your database, each for a different purpose.

Each table is recognized by its name. To open a particular table, you can double-click it. You can also right-click a table's name and click Open. If the desired table is already selected on the Database Window, you can click the Open button to open it.

 

Practical Learning: Opening a Table

 

 

  1. On the Database Window, in the Objects Bar (Microsoft Access 2000) click the Tables button or the Tables property page (97)
  2. Double-click Employees
     
  3. To close the table, click its Close button

 

Database Objects: Queries

 

 

A table can be large depending on the information it holds. To further organize your data, you should be able to retrieve necessary information for a specific purpose. The solution is to create a query (or queries) in order to limit part of the data in a table for a specific goal, for better managing or searching. That's the role of a query.

Just like tables, queries are managed from the Database Window in their own category. You can open a query the same way you open a table.

 

Practical Learning: Opening A Query

 

 

  1. On the Database Window, in the Objects Bar (2000) click the Queries button or the Queries property page (97)
  2. Double-click List of Registrants By T-Shirt Size to open it:
     
  3. After viewing the query, to close it, click its Close button

 

 

Notes

Queries and tables look alike. As you will see in future lessons, their main difference is noticed only behind-the-scenes. This has to do with the way each receives its data.

 

Database Objects: Forms

 

 

Tables are used to create the data in your database, but they are usually not friendly looking, as far as the users are concerned. Forms are windows objects used to view and/or enter data in your database.

A form can combine data that is part of one or more tables or queries. Forms are the window interfaces that you usually will ask your users to access when performing data entry in your database.

 

Practical Learning: Opening A Form

 

 

  1. On the Database Window, click Forms
  2. Double-click MembersByGender
     
  3. After viewing the form, click its Close button dismiss it

 

Database Objects: Reports

 

 

A report is the organized document that allows a user to print information from a database. A report can include different parts or details about your database. It could include data from a table or a query, it could also get its data from various tables, queries, forms, or data that is calculated from other data coming from different tables or forms. You could also create a completely independent report whose content is not related to any data on an object.

 

Practical Learning: Opening A Report

 

 

  1. On the Database Window, click the Reports button
  2. Double-click Camps
     
  3. After viewing the report, click its Close button Close

 

Database Objects: Pages

 

 

Starting with Microsoft Access 2000, Data Access Pages allow you to publish your forms as web pages on the Internet or on an Intranet. Their use is not as common as the other database objects but they provide thoughtful functionality.

Notes

The following exercise cannot be performed on Microsoft Access 97.

 

Practical Learning: Data Access Pages

 

 

  1. On the Database Window, click the Pages button
  2. Double-click Camps
     
  3. After viewing the page, click its Close button 

 

Macros

 

 

When creating Microsoft Access databases, you can customize certain behaviors of your products. Some of these behaviors can be automated through a combination of buttons. For example, you may want to open one document (form) from another. You can use macros to do that. In such case, you would not have to write code. Since macros are becoming less and less popular (for good reasons), we will not spend much time learning them.

 

Modules

 

 

Modules are pieces of code used to impose particular behaviors to your application to make it better. They are written in Microsoft Visual Basic. Modules are more flexible and extensive than macros, although they are usually written for various and particular circumstances. One example is to print a receipt after a customer has bought paint in a store.

Macros and Visual Basic code can be used on the same application. Sometimes you will prefer one to the other, and sometimes you will keep using VBA (Visual Basic for Applications). Whenever possible, you should use VBA instead of macros.

Although modules are represented on the Database Window like the database objects we have seen so far, to view, read, or access a module, you need to get to Microsoft Visual Basic. There are various ways you could do that. A module could be an independent piece of code that is not related to another object, in this case its name would appear in the Database Window; all you have to do is double-click it and that would launch Microsoft Visual Basic. If you select a form or report from the Database Window, you will see the Code button on the Database toolbar. If you click that button, it would launch Microsoft Visual Basic. If the form or report has some code associated (or bound) to it or to some of its controls, the code would display; otherwise the programming window look empty (it should have at least one line displaying Option Compare Database.

 

Practical Learning: Opening Microsoft Visual Basic

 

 

  1. On the Database Window, click Modules
  2. Double-click modUtilities
  3. Notice that Microsoft Visual Basic opens (if you are using Microsoft Access 97, you should see a window called the Code Window):
     
  4. To return to Microsoft Access, click the View Microsoft Access button (if you are using Microsoft Access 97, close the Code window by clicking its Close button )
  5. To close the form, click its Close button 

 

Microsoft Access Help

 

 

 

Context-Sensitive Help

 

Context-sensitive help refers to help provided on a specific item on the screen. Such help is provided for objects that are part of Microsoft Access interface. It includes objects like buttons on toolbars, an object opened such as a table, a query, a form, or a report, etc. Context-sensitive help is also referred to as “What’s This?”.

To get context-sensitive help, press Shift + F1. In addition to the traditional arrow, the mouse cursor would be accompanied by a question mark. To get help on an object, you can just click it.

Another type of context sensitive help is provided in various dialog boxes. They display a button with a question mark on the left of the system Close button. To use this type of help, click the question mark button and click the item on which you need help.

 

Practical Learning: Using Context-Sensitive Help

 

  1. Press Shift + F1 and notice the new mouse cursor
  2. On the Database toolbar, position the mouse on the Open button
     
  3. Click
     
  4. After viewing help, press Esc
  5. To get context-sensitive help on a dialog box, on the main menu, click Insert -> Form
  6. In the New Form dialog box, click the What’s This button 
     
  7. Click the list box in the middle right side of the dialog
     

     
  8. After viewing help, click the What’s This button again and click the combo box, in the bottom right side of the dialog box
     
  9. After viewing help, press Esc and click Cancel

 

 

 

 

 

 

 

The Office Assistant

 

 

The Office Assistant is a “character” or a “virtual person” whose main job is to provide instant help when using a Microsoft Office product. The Office Assistant is usually on top of Microsoft Access while you are working. If you do not like the way it looks, you can click it and click Options. This would present you with the Office Assistant property sheet in which the Gallery property page allows you to select a different Office Assistant. The Options property page allows you to configure the behavior and responsiveness of the Office Assistant.

To use its service, just click it, then type a word, a sentence, or a question. After pressing Enter, a primary list of possible matches would be displayed. If you do not find what is close to your request, you can use the available options or change your request.

If you do not want the Office Assistant on the screen while you are working, you can hide it. To do this, in Microsoft Access 97, you can click its Close button. In Microsoft Access 2000, on the main menu, you can click Help -> Hide Office Assistant. To display it when it is not available, on the main menu, you can click Help -> Show the Office Assistant.

 

Practical Learning: Using the Office Assistant

 

 

  1. If the Office Assistant is not displaying on the screen, on the main menu, click Help -> Show Office Assistant
    To use the Office Assistant, click it
  2. Type Create Table
     
  3. Click Search
  4. On the list that appears, click Create a table
  5. On the HTML Help window that appears, read the text and click one of the blue links
  6. After reading it, on the toolbar of the HTML Help window, click the Back button
     
  7. Click another link
  8. After reading it, close the HTML Help window that opened but do not close Microsoft Access
  9. In Microsoft Access, click the Office Assistant again. Notice that the last request re-displays. Click Search
  10. This time, click See More…
  11. In the second page, click another link such as Create A Field For Text Or Memos
  12. Do not perform but read the instructions. After reading the instructions, close the HTML Help window

 

Online Help

 

 

Online help is a separate program that provides help on Microsoft Access. There are two main types of online help:

  • Microsoft Access ships with help available from the main menu. To use it, you can click Help to display the list or available categories. The most direct way of accessing help consists of clicking Microsoft Access Help. This would bring up the Office Assistant and you would proceed as we did above
  • If you have access to a Microsoft Developer Network (MSDN) CD-ROM or DVD, which is the help system provided to programmers who use Microsoft technologies (such as Microsoft Visual Studio), it includes a section on Microsoft Office, which internally includes a sub-category on Microsoft Access. On that help system and in the left frame, you can expand the link that displays Office. Then visit links to Microsoft Access or Microsoft Office:
     

 

 

It is important to note that help in Microsoft Access 2000 and above is different than help in Microsoft Access 97. In the 97 version, help was provided through a system called WinHelp. After that, Microsoft decided to start using HTML Help. Like everything in computer applications, each of these help systems has its advantages and disadvantages. Over all, the process of getting help remains the same but it is displayed differently.

 

Internet Help

 

 

Although help on the Internet tends to be disparate, it is still the widest form of help available. This is provided in web sites, web pages, newsgroups, support groups, etc. As the publisher of the database environment, it is only natural to refer to the Microsoft corporate web site first for help. The Microsoft web site is divided in categories. A web site is dedicated to Microsoft Access at http://www.microsoft.com/access. You can get help at http://support.microsoft.com. Probably the most visited site of Microsoft for developers of all Microsoft products is http://msdn.microsoft.com. This last site provides a tree-based list that presents items in categories.

 

Microsoft Access Exit

 

 

Since Microsoft Access shares the same functionality you are probably familiar with from using other applications, you can close it easily.

  • To close Microsoft Access, from the menu bar, you can click File -> Exit
  • To close Microsoft Access from the system icon, you can either click it and click Close, or you can double-click its system icon
  • To close Microsoft Access from its title bar, you can click its Close button
  • To close Microsoft Access like any regular window of the Microsoft Windows applications, you can press Alt + F4
  • To close Microsoft Access using mnemonics, you can press Alt, F, X.

 

Practical Learning: Closing Microsoft Access

 

 

  • To close Microsoft Access, click the Close button on the top right corner of the window

 

MOUS Topics

 

 

S4

Use the Microsoft Office Assistant

S5

Select an object using the Objects Bar

 

Exercises

 

 

Bethesda Car Rental

 

 

  1. If you have Internet connection, go to http://www.kbb.com
  2. Perform a search to look for a Retail 1996 Honda Accord DX Sedan 4D
  3. During your search, change different options and mileage and verify how the price changes

 

US Senate

 

 

  1. Go to http://www.senate.gov
  2. Review the names of senators and all available information about them
  3. Find the name of the Chairman of the Finance Committee.

 

2.

Introduction to Data Sheets

 

 

 

Creating a Database

 

 

The Database Wizard

 

 

Many techniques allow you to create a database, the fastest of which consists of using one of the provided examples. Microsoft Access 97 shipped with 22 sample databases while Microsoft Access 2000 ships with 10. Furthermore, the 97 version allowed to provide sample data into the database. This is not available with the 2000 release. The databases that ship with Microsoft Access can help you in two main ways: they provide a fast means of creating a database and you can learn from their structure.

Data Wizard

 

To create a database using one of the samples, there is a little detail to follow depending on whether you had launched the program already or not. If Microsoft Access is not running, you can start it. When the first dialog box comes up, you can click the second radio button: Access Database Wizard, Pages, And Projects and click OK. If the program is already on your screen, on the menu bar, click File -> New Database…

The New dialog box displays two property pages labeled General and Databases. If you want to create a database based on one of the samples, you can click the Databases property page. A list of the sample databases appears. You can then choose one and click OK.

When creating a database using one of the samples, depending on the sample you selected, the Database Wizard will display a few objects and suggest some fields for your database. Some fields are already associated with the objects and some other fields can be added. You can examine them, then add some fields you think are important for your database. You will also have the option of selecting a design layout. Some of the sample databases have been configured to require information about the company you are creating the database for..

 

Notes

An application is said to be running if it is displaying on your screen.

 

Notes

If you have both Microsoft Access 97 and Microsoft Access 2000 installed on your computer, the New dialog box would display 3 property pages.

 

Practical Learning: Creating a Database Using a Sample

 

 

  1. Start Microsoft Access if necessary and click the second radio button.
    If you are using Microsoft Access 97, it is the Database Wizard radio button.
    If you are using Microsoft Access 2000, it is the Access database wizards, pages, and reports radio button
     
  2. And click OK. This opens the New dialog
  3. From the New dialog box, click the Databases tab if necessary and, from the Databases tab, click Time and Billing
     
  4. Click OK
  5. Locate the Exercises folder and display it in the Save In combo box
  6. Delete the content of the File Name text box of the File New Database dialog box and type Rockville Techno and click Create
  7. When the first page of the wizard comes up, click Next
  8. For this exercise, on the Tables In The Database list box, click Information About Employees:
  9. On the Fields In The Table list, click the Employee Number check box
     
  10. Click the check box of Email Name
  11. Scroll down and click the Home Phone check box
  12. Click Next
  13. For the style of the screen display, choose International to preview one of the samples and click Next
  14. For the style of the printed report, click Bold to preview that display
  15. Click Formal and click Next
  16. For the title of the database, type Rockville Technologies
     
  17. Click Next
  18. Then click Finish
    While the Database Wizard is creating a database for you, dialog boxes will be flashing from time to time. If you don't have a printer, a nasty dialog box will be giving an error. If this happens, click OK all the time. In this case, after this lesson, use the Add Printer wizard from the Printers window to install a "fake" printer. One way or another, Microsoft Access needs a printer for the reports
  19. When asked to provide information about your customer, click OK
  20. In the Company Name text box, type Rockville Technologies, Inc. and press Enter
  21. In the Address text box, type 5026 Towers Road Suite D14 and press Enter
  22. In the City text box, type Rockville and press Enter
  23. In the State field, type Maryland and press Tab
  24. In the Postal Code field, type 20852-1644 and press Tab
  25. In the Country field, type USA and press Tab
  26. In the Payment Terms, type 60 Days
  27. Click the Invoice Description field and type For more information on our company, visit us at http://www.rockvilletechnologies.com
  28. Press Tab
  29. In the Phone Number field, type (301) 869-9814 and press Tab
  30. In the Fax Number field, type (301) 869-9618
     
  31. After entering the necessary data for your customer, to close the company's form, click its system Close button
  32. Notice that the database opens with the switchboard.
    To close the switchboard, click its system Close button
  33. On the lower left corner of MS Access, click the bar of the Database window and, on the menu that appears, click Restore

 

 

Database Properties

 

 

Your screen may be made of a large box at this time: this is the Switchboard, and it is a form. A special window you will be using most regularly is called the Database Window. Whenever it is minimized or hidden, you can display it by pressing F11 (unless it has been configured to (almost) never display).

Whether you work alone or in a group, communication and documentation are important. Your database project has its own properties that you can

 

use to find out some details about your file, to enter some notes about the project, or to give directives to other people who have access to the database. 

 

Practical Learning: Using Microsoft Access

 

 

  1. The Rockville Technologies database should still be opened
    To display the Database Window, press F11
  2. On the main menu, click File and observe the menu items under File
  3. While the File menu is still selected, move the mouse to Tools and click Startup… 
  4. The Startup dialog box allows you to set some settings that the current database will follow when it starts.
    In the Application Title, type Rockville Technologies, Inc.
  5. Click the arrow of the Display Form/Page combo box and select (None). In case you wonder why (None) is between parenthesis, this is done so that if there are other things in the list, None would always be on top of the list. That way, it would not be between two other objects (forms and Data Access Pages) on the list.
  6. Click the browse button of the Application Icon text box
  7. On the Icon Browser dialog box, locate the folder that holds the resources for our lessons
  8. Click the Rockville Techno icon and click OK
  9. Accept all the other defaults:
     
  10. Click OK
  11. Notice that, on the title bar, the database is now using another icon than the default one
  12. On the main menu, click Tools -> Options…
  13. The Options dialog box allows you to control some settings that are related to Microsoft Access.
    For example, click the General tab
  14. Change the content of the Default Database Folder text box to the Exercises folder you will be using throughout our lessons
  15. Increase the Recently Used File List combo box to 8
     
  16. Click OK
  17. As mentioned already, each toolbar on the database has a particular name. To find out the name of the current toolbar, right-click any button on it
  18. Notice that the Database name has a check box. This means that toolbar is displaying at this time. In this case, this toolbar is called the Database Toolbar
  19. On the menu bar, click File -> Database Properties
  20. Once more, from the menu bar, click File -> Database Properties
  21. From the Properties dialog, click the General tab. Examine the various sections. Notice the size of the current database
  22. Click the Summary tab
  23. Make sure the Title is set to Rockville Techno
    Click the Subject text box and type Business Regular Activities 
  24. Click the Author text box and type Lucien Durand
  25. Click the Manager text box and type Christine Lotts
  26. Click the Company text box and type Rockville Technologies, Inc.
  27. Click the Category text box and type Business
  28. Click the Keyword text box and type business, clients, projects, transactions
  29. Click the Comments text box and type: This software product is used by the company to conduct its regular business activities and related transactions. For more information, contact Lucien Durand or Christine Lotts. Refer to the Address Book for their phone number, extension, and E-Mail Address.
  30. Click the Hyperlink Base text box and type http://www.rockvilletechnologies.com
     
  31. Click the Statistics, Contents, and Custom property pages and review their contents.
    The Statistics tab gives you statistics about your database and its summary access.
    The Contents tab shows a list of the components that are part of your database.
    The Custom tab shows, and allows you to customize, the field names associated with your database.
  32. When you have finished working with the database Properties, click OK (if you click Cancel, any change(s) you have made will be discarded)

 

 

Tables Fundamentals

 

 

 

The Table Wizard

 

 

Microsoft Access is filled with wizards which are step-by-step dialog boxes that allow you to create objects or fields on a database. Like the Database Wizard, Microsoft Access provides the Table Wizard used to easily create a table. It allows you to add fields that are necessary for a particular table. The fields have been configured in the general sense so you can use them in your database. Of course you can modify any field that was created using

the wizard. To use the Table Wizard, on the main menu, you can click Insert -> Table. Alternatively, on the Database Window, when in the Tables section, you can click the New button. These two actions would display the New Table dialog box from where you would select Table Wizard. If you are using Microsoft Access 2000 and later, from the Tables section of the Database Window, you can double-click Create Table By Using Wizard
 

In the Table Wizard, the tables are organized in two primary categories: Business and Personal. To select one of those categories, you can click its radio button. Each main category is made of various sample tables. To select a sample table, you can click its name in the Sample Tables list. In the middle, the Sample Fields list, the fields associated with the selected sample table are displaying. From that list, you can select the desired field(s). Once a field has been selected, it displays in the Fields In My New Table list. You can then select a different table to mix fields from as many tables as desired. The 4 buttons between the Sample Fields list and the Fields In My New Table list allow you to add or subtract fields. To help with selection and de-selection, the wizard provides four buttons:

 

Button

Role

Used to select one field

Used to select all fields from the sample table

Used to deselect one field

Used to deselect all fields

During field selection, if you select a field, its corresponding name appears in the right list. If you select a field of the same name more than once, for example, if you select Address twice, the 2nd Address would be called Address1. Sometimes that will be what you want, and sometimes it will be by mistake. If then you make a mistake when selecting fields, you can double-click the unwanted field in the Fields In My New Table list and that field will be removed.

After making your choices, you can keep the names provided by Microsoft Access into your table, or you can rename any field to suit your needs. To rename a field, first select it in the Fields In My New Table list. Then, click the Rename Field button. In the Rename Field dialog box, type the desired name and click OK:

If you try providing a name for a field that already exists, you would receive an error:


 

 

 

Practical Learning: Using the Table Wizard

 

 

  1. The Rockville Techno database should still be opened
    In the Database Window, click the Tables button
  2. Double-click Create Table By Using Wizard. (If you are using MS Access 97, from the Tables tab, click New and double-click Table Wizard). The Table Wizard starts
  3. Click the Business radio button if necessary
    In the Sample Tables list box, scroll down and click Assets
  4. In the Sample Fields, click AssetID and click the Select One Field button 
  5. From the Sample Fields, double-click Make, Model, ModelNumber, SerialNumber, DateAcquired, and PurchasePrice
  6. In the Sample Tables, scroll up and click Mailing List
  7. In the Sample Fields, scroll down and double-click Notes
  8. In the Fields In My New Table list, click ModelNumber to select it and click the Remove One Field button 
  9. Click the Personal radio button
  10. In the Sample Tables, click Categories
  11. In the Fields In My New Table list, click AssetID to select it
  12. From the Sample Fields, double-click CategoryName 
  13. In the Fields In My New Table list, click CategoryName to select it and click the Rename Field… button
  14. In the Rename Field, change the Field Name to AssetType
     
  15. Click OK
  16. Click Next
  17. Change the name of the table to CompanyAssets
  18. Click Next twice and click Finish
  19. To close the CompanyAssets table, click its system Close button 

 

Data Entry on Tables

 

 

Data is entered in a table by typing it into cells. Some fields can be configured to accept some types of data and reject others. Some other fields would allow anything. This depends on how the database fields were setup.

A table's cell holds one particular unit of data. All cells on the same (vertical) column belong to the same category of information. The horizontal range of cells is called a record; and all cells on this range belong to the same record.

 

After typing data into a cell, you can press Enter or Tab to move the cursor to the next cell. In many circumstances you will also be able to move to the next cell by pressing the right arrow key. Sometimes you can move to the next record even if the current record is not completed. In this case, you could press the down arrow key.

There are three kinds of fields or cells the user will face: a field in which the user can type data, a field that displays a list such as a combo box the user has to select from, and a field that does not receive input from the user. The latter is usually set for an AutoNumber data type: the database itself keeps track of the numbers. If you as the user have to select from a list, click the field that holds the list and select from the combo box. There are two kinds of combo boxes, those that accept new entries from the user and those that allow only a selection from a preset list. The classic field allows the user to just type the appropriate data in a field.

After setting the data in a particular field, you can click another cell and type the desired data. The easiest way is to press the right arrow key to move to the next field or the left arrow to move to the previous field; pressing Enter would work as well.

Data on the same row represents a record. Data on the same column represents a category. After typing data, if you press Enter at the end of a record, the cursor would move to the beginning of the next record. At anytime, you can press the up arrow key to move to the same category field of the previous record. If you press the down arrow key, the same category of the next record would receive focus.

 

Practical Learning: Table's Data Entry

 

 

  1. The Rockville Techno database should still be opened
    On the Database window, while in the Tables section, double-click the CompanyAssets table to display it
  2. Click the first empty field under AssetType and type Printer 
  3. Press Enter and type HP
  4. Press Tab and type LaserJet 4200dtn
  5. Click the empty box under Date Acquired and type 10/08/2002 or 10/08/02 depending on how your computer is setup (we will discuss this during Database Maintenance but for now, if your computer is configured for a two-digit year, enter only the right two digit of the year)
  6. Complete the table as follows:
     

AssetType

Make 

Model 

Date Acquired

Purchase Price

Notes

Printer

HP 

LaserJet 4200dtn

10/08/2002

1950.95

B/W Printer

Computer 

IBM 

NetVista M42

10/08/2002

1035.00

 

Laptop 

Gateway 

200XL 

12/05/2002

2095.95

Business Notebook

Printer 

Xerox 

Phaser 8200

10/22/2002

1250.55

Color Printer

Digital Camera

Olympus 

C-50

11/06/2002

450.75

 

Computer

IBM 

ThinkCentre S50

10/08/2002

1055.55

 

  1. Close the CompanyAssets table
  2. On the Database window, right-click the Payment Methods table and click Open
  3. Complete it as follows:
     

Payment Method ID

Payment Method

Credit Card?

1

Check 

No

2

Cash 

No

3

Money Order

0

4

Visa 

1

5

Master Card

-1

6

American Express

58

  1. Notice that the 0 value changes into No and any other number changes into Yes
  2. To close the Payment Methods table, click its system Close button
  3. On the Database window, double-click the Employees table to open it
  4. Click the first empty field under Last Name, type Phillips and press Enter
  5. Perform data entry, skipping other fields
  6. Close the table after performing data entry 

 

Table Printing

 

 

The primary function of the table is to provide a means of storing and arranging information of a database. Nevertheless, you can print data of a table, especially if either you do not have appropriate reports available or you are in a hurry. You can print data on a table whether the table is opened or not.

To print a closed table, locate it in the Database Window. Then right-click the desired table and click Print. 

 

Once a table is opened in Datasheet View, on the Table Datasheet toolbar, you can click the Print button. This will send all the records of the table to the printer for printing.

If you want to control the printing process, instead of using the Print button, on the main menu, you can click File -> Print... To print data of all fields on the table, you can click OK. If you want to print only certain records, unfortunately, Microsoft Access does not allow you to select rows at random: you can only select a range of records. To print a range of records, while a record at one end has focus, you can press and hold Shift. Then click the gray box at the end of the range.

 

Practical Learning: Printing Tables

 

 

  1. To reopen the Payment Methods table, on the Database Window, while in the Tables section, double-click Payment Methods
  2. To print data from the table, on the Table Datasheet toolbar, click the Print button
  3. To close the current table, click its system Close button
  4. To print the list of the company’s assets, on the Database Window, click the CompanyAssets table to select it (you don't have to open it)
  5. On the main menu, click File -> Print… (if you are using MS Access 2000, you may need to double-click the File menu to display the whole list, which includes Print...)
  6. Make sure a printer is selected in the Name combo box
    Click the Properties button
  7. Based on your printer, select the Landscape radio button (usually in the Orientation section of a Paper tab) and click OK
  8. On the Print dialog box, click OK
    (If you had opened a table, you can close it now)
  9. Open the Employees table
  10. To print only the names of employees, click David. Press and hold Shift. Then click Network Administrator
  11. On the main menu, click File -> Print…
  12. On the Print dialog box, click the Selected Record(s) radio button and click OK
  13. After using the table, close it

 

 

Queries Fundamentals

 

 

 

 

The Query Wizard

 

A query is a request you present to the database, and the database displays its response to you. The whole purpose of creating a query lies on how you formulate that request. There are three main ways you create a query in Microsoft Access:

  • The Query Wizard offers the simplest approach where in a step by step process you define the purpose of the query and the database will display its answer
  • The best way to build a query is by using the Design View
  • Once you get familiar with queries, you will find out that a query is just a group of words called a statement you formulate. This means you can write that statement manually. This approach is the most complex because you need to know the structure of a query statement, but it provides more control than the other two techniques.

The simplest way to create a query is by using the Query Wizard. The wizard presents the tables that are part of the database and you select which fields you need. Such a query is called a Select Query.

Data used on a query can originate from a table, another query, or a combination of tables and/or queries. The first page of the Simple Query Wizard expects you to choose the origin of the query, starting with the table or the query name. For example, you can use a table of employees, then, you choose the necessary data that you want to filter for your query. You can use this query to retrieve the employees' data by their employee number, their last name, the date they were hired, their salary, their marital status, their E-Mail address, or the city or state they live in.

To use the Query Wizard, on the Database Window, you can click the Queries button and then double-click Create Query By Using Wizard. Alternatively, you can first display the New Query dialog from where you would choose Simple Query Wizard. To display the New Query dialog box:

  • On the toolbar of the Database window, while in the Queries section, you can click the New button
  • On the main menu, you can click Insert -> Query
  • On the Database Toolbar, you can click the arrow of the New Object button and click Query

When building a query in the first page of the Simple Query Wizard , you must first specify the object (a table or another query) that will provide data. Then select items using the same types of buttons we reviewed for the Table Wizard.

 

Practical Learning: Creating a Query Using The Wizard

 

  1. The Rockville Techno database should still be opened
    On the Database Window, click the Queries button
  2. To create a query, from the Database window, double-click the Create Query By Using Wizard button
    (If you are using MS Access 97, click New, click Simple Query Wizard, and click OK)
  3. From the Tables/Queries combo box, select Table: CompanyAssets
  4. From the Available Fields list box, double-click AssetType, Make, Model, DateAcquired, and PurchasePrice
     
    Simple Query Wizard
  5. Click Next twice
  6. Give the title AssetsInventrory and make sure the Open The Query To View Information radio button is selected
     
  7. Click Finish

 

 

 

Data Entry on a Query

 

 

A query uses the same approach to present its data, like a table: it is made of columns and rows whose intersections are cells. Although the main purpose of a query is to prepare data either for analysis or isolate some fields to make them available to other database objects, as done on a table, data can be entered in a query.

 

Data entry on a query is the same as done on a table: data is entered into cells. The Enter, Tab and arrow keys are used with the same functionality. Like the table, the query provides navigation buttons on its lower section, allowing you to move to the first, the previous, the next, the last or any record in the range of those available. 

 

Practical Learning: Performing Data Entry on a Query

 

 

  1. While the AssetsInventory query is still opened, click the first empty field under the AssetType column
  2. Type Computer and press Enter
  3. Complete the query as follows:
     

AssetType

Make 

Model 

Date Acquired

Purchase Price

Notes

Printer

HP

LaserJet 4200dtn

10/08/2002

1950.95

B/W Printer

Computer 

IBM 

NetVista M42

10/08/2002

1035.00

 

Laptop 

Gateway 

200XL 

12/05/2002

2095.95

Business Notebook

Printer 

Xerox 

Phaser 8200

10/22/2002

1250.55

Color Printer

Digital Camera

Olympus 

C-50

11/06/2002

450.75

 

Computer

IBM 

ThinkCentre S50

10/08/2002

1055.55

 

Computer

Ctrl + '

Ctrl + '

10/20/2002

1120.55

 

Ctrl + '

Ctrl + '

Ctrl + '

Ctrl + '

Ctrl + '

 

  1. After using the query, close it
  2. To create a query of selected information of employees, on the main menu, click Insert -> Query
     
  3. In the New Query dialog box, click Simple Query Wizard and click OK
  4. In the first page of the wizard, in the Tables/Queries combo box, select Tables: Employees
  5. In the list of Available Fields, double-click FirstName, LastName, Title, and BillingRate
  6. Click Next twice
  7. Change the Title of the Query to Employees Pay Information and click Finish
  8. After viewing the result of the query, close it

 

Query Printing

 

 

Like tables, queries provide you with a fast means of printing data. Once again, this should be done when you need a printed but not a professional-oriented product. Data printing on a query is done with the exact same approaches and techniques as for a table.

 

Practical Learning: Printing a Query

 

 

  1. On the Database Window, while still in the Queries section, double-click the AssetsInventory query
  2. To print the query, on the main menu, click File -> Print…
  3. Make sure a printer is selected in the Name combo box and click the Properties button
  4. Select the Portrait orientation and click OK
  5. Click OK on the Print dialog box
  6. To print only a few records, click the gray box on the left side of Laptop
  7. Press and hold Shift. Then click the gray box on the left side of Digital Camera and click release Shift
     
  8. On the main menu, click File -> Print… and, on the Print dialog box, click Selected Record(s)
  9. Click OK to print
  10. After using the query, close it. 

 

MOUS Topics

 

 

S6 

Print database objects (tables and queries)

S7

Navigate through records in a table, query, ...

S8

Create a database (by using a wizard ...)

S9

Create tables by using the Table Wizard

S23

Enter records using a datasheet

 

Exercises 

 

 

Tenley Associates

 

 

  1. Start a new database using the Database Wizard and based on the Expenses sample database
  2. Name it Tenley Associates
  3. For the Information About Employees, add Department Name, Email Name, Home Phone, and Date Hired
  4. For the Expense Report Information, include the Business Purpose
  5. Set the Screen Style to Stone
  6. Set the Printed Reports Style to Corporate
  7. Set the Database Title to Tenley Associates
  8. Set the Startup form to None
  9. From the Tables section of the Database window, open the Expense Categories table and enter the following expenses:
     

Expenses Category ID

Expenses Category

Expense Account#

1

Office Equipment

102

2

Car Rental

104

3

Transportation

105

4

Customer Entertainment

108

5

Other

112

  1. Print all records on the table and close it
  2. Open the Employees table and fill it up with the following values, ignoring those not mentioned:
     

First Name

Last Name

Title

Home Phone

James

Bidds

Accountant

(301) 725-4570

Alexandra

Roberts

Sales Manager

(410) 727-0982

Walter

Hoaks

Sales Representative

(410) 521-2850

Bertine

Baugh

Manager

(301) 912-2129

  1. Close the table
  2. Using the Simple Query Wizard, create a query based on the Employees table and include the following fields: FirstName, LastName, Title, and HomePhone. Save the query as Employees Contact Information
  3. Close the query and print all of its records without opening it
  4. Using the Employees Contact Information query, print only the second and third records of employees
  5. Use the Table Wizard to create a table that includes the following fields: DepartmentID (from the Assets sample table), DepartmentName (from the Employees sample table), and Notes (from the Recipes sample table of the Personal category). Save the table as Departments and fill it up with the following values
     

Department ID

Department Name

Notes

1

Administration

Including all personnel from Management

2

Sales

Including all sales representatives and managers

3

Accounting

 

 

3.

Introduction to Forms and Reports

 

 

 

Forms Fundamentals

 

 

Introduction

 

 

As done for the tables and queries, Microsoft Access provides a central dialog box you can use to create forms: this is the New Form dialog box. To display the New Form dialog box, if no object is opened, on the main menu, you can click Insert -> Form. Alternatively, in the Database window, you can first click the Forms button. Then, on the toolbar of the Database window, you can click the New button.

 

As done for a query, before creating a form, you must decide where data would come from. If you are creating an independent form whose fields are made of Windows controls and whose contents would not depend on any field or data stored in another object, you can just proceed as you see fit, as if you were developing a regular Windows application. If you are creating a form meant for data entry for the database, you should specify where its data would come from. The object can be a table, a combination of tables, a query, a combination of queries, or a combination of tables and queries. If the data of a form will be based on such an object or a group of objects, you must specify it, before or while creating the form.

 

AutoForm

 

 

The fastest means of creating a form is through a feature called AutoForm. To use AutoForm, you can first select a table or a query on the Database window; you don't have to open the object. If the table or query is selected in the Database window, to create a form in one step, on the Database toolbar, either click the AutoForm button if it is already selected, or click the arrow of the New Object button and click AutoForm. Alternatively, while a table or a query is selected in the Database window but not opened, to quickly create a form, on the main menu, you can click Insert -> AutoForm. If a table or a query is already opened and you want to create a form based on it, on the Table Databasheet toolbar, or on the Query Datasheet toolbar, you can click the AutoForm button if it is already set as the New Object or you can click the arrow of the New Object button and click AutoForm.

Another technique used to create a form using AutoForm consists of first displaying the New Form dialog box. From there you can click one of the three AutoForm options, select the object that holds data and click OK.

 

Practical Learning: Using AutoForm

 

 

  1. Open the Rockville Techno database you created in the previous lesson
  2. On the Database window, click the Queries button and click the Employees Pay Information query to select it
  3. On the Database toolbar, position the mouse on the New Object button. If the tool tip displays New Object: AutoForm, , then click it. If it displays something else, click the arrow of the New Object button and click AutoForm

  4. After viewing the form, on the Form View toolbar, click the Save button
  5. Accept the suggested name for the form by clicking OK
  6. Then close the form

 

 

 

The Form Wizard

 

 

As far as users are concerned, the form is the central point of a database. It is used to view, enter, manipulate, and search data. Because users spend a great deal of their time looking at forms, you should create and make them as attractive and friendly as possible. Form design can take a long time in database development but Microsoft Access provides quick means to get around.

 

The Form Wizard provides an easy and fast means of creating a form. Like the other wizards we have used so far, this one also takes you step by step through creating the object. There are two main ways you can launch the Form Wizard: from the Database Window or from the New Form dialog box. On the Database Window, you can click the Forms button. Then double-click Create Form By Using Wizard. On the New Form dialog box, you can click Form Wizard and click OK.

The first page of the Form Wizard allows you to choose the originating table or query that will supply the necessary fields in the form. Once you have selected the object, its corresponding fields display in the Available Fields list box. You can then select all fields or decide which ones you want to include in the form.

The 2nd page of the wizard allows you to select the desired layout of the form. Forms can be designed in various flavors: Columnar, Datasheet, Tabular, Justified

  • A columnar form is used to display data one record at a time. This is a convenient display for data entry and analysis because the user is able to examine each piece of information for each one record:
     
  • A tabular form displays its data in a table layout following a continuous series of records. All or almost all records are displaying in a single layout:



    There are three main ways you can create a tabular form: from the New Form dialog box, using the Form Wizard, or designing it
  • A datasheet form looks and behaves like a table, displaying all possible records at the same time instead of one record at a time:


     
    A datasheet form is mainly used in relationships to display another table's related records. It is also suitable for people who prefer to work in a spreadsheet environment. This display allows the database developer to provide a sheet view to the data entry personnel without making the table's design or formats available.

    You can make the same form available in Form View and Datasheet View. In fact, most forms are. Users can switch from Form View to Datasheet View by clicking the View menu. Unfortunately, this could also allow the users to get the form in Design View, and then they could modify it. If you do not want the users to have access to Design View but retain Form View and Datasheet View, you may have to create custom menus and toolbars.

    There are two main ways you can create a Datasheet form: using the wizard or designing it.
  • A Justified form provides a good and consistent look. When the form is created, borders are added to labels:
     


    The 3rd page of the Form Wizard presents the forms designs you can choose from. These are the designs we saw when creating a database using the Database Wizard.

    The 4th page allows you to name the form.

 

Practical Learning: Form Wizard - Columnar

 

 

  1. The Rockville Techno database should still be opened
    On the Database Window, click the Forms button
  2. On the Database Window’s toolbar, click New
  3. On the New Form dialog box, click Form Wizard
  4. From the combo box, select the CompanyAssets
     
    New Form
  5. Click OK
  6. Click the Select All Fields button 
  7. Click Next
  8. Accept or choose the Columnar layout, then click Next
  9. Click the International style and click Next
  10. Accept the name of the form as CompanyAssets and click Finish
    An automatic form is created for you
     
    Company Assets
  11. To close the form, click its Close button

 

Data Entry on a Form

 

 

Data entry of a database is mainly performed on forms as they provide the friendliest display of information. Data entry on a form is performed using text boxes, combo boxes, and other controls. On text boxes, the user enters data by typing it. On a combo box, depending on how the object was configured by the database developer, the user may have to only select an item from the list. In some other cases, the user may be allowed to enter new data.

 

After entering or changing data on a control, to move from one field to the next, the surest way is to press Tab. On most occasions, the user can also press Enter. The Enter key may not move the cursor from a text box that allows multiple lines of text (such as a field created as Memo). If the user is simply reviewing data without performing data entry, the keyboard’s arrow keys can also be used to move among fields.

 

Practical Learning: Form Data Entry

 

 

  1. The Rockville Techno database should still be opened and the Forms button should be selected. Otherwise, on the Database Window, click the Forms button
    Double-click the Employees form to open it
  2. In the first record, for David Phillips, click Address and type 10048 Venice Drive
  3. Press Enter to move to the City field and type Bethesda
  4. Complete each record by clicking in the appropriate field and typing the corresponding data (after each record, click the Next Record button)
  5. Close the Employees form after performing data entry
  6. Double-click Expense Codes
  7. In the first Expense Code, type Office Supplies and press Enter
  8. Type Software and press Enter 
  9. Type Printer and press Enter 
  10. Type Computer Supplies and press Tab 
  11. Type Car Rental and press Tab 
  12. Type Air Fare and press Tab 
  13. Type Meal 
  14. To close the form, click its system Close button
  15. Double-click Work Codes 
  16. In the first Work Code, type Regular and press Enter 
  17. Type Web Design and press Enter. 
  18. Type Data Entry and press Tab 
  19. Type Database Design and press Tab 
  20. Type Software Coding 
  21. To close the form, click its close button 
  22. Double-click Clients 
  23. In the First Name text box, type Jose and press Enter 
  24. In the Last Name text box, type Marillo and press Enter 
  25. In the 8012 Herald Ave Suite 402 and press Enter 
  26. In the City text box, type Alexandria and press Tab 
  27. In the State/Province text box, type VA and press Tab 
  28. In the Postal Code text box, type 22031 and press Tab 
  29. In the Country text box, type USA 
  30. Click in the Company Name text box and type PTN Investors, Inc. 
  31. Click in the Contact Title text box and type Director of Investments and press Tab
  32. In the Phone Number text box, type 7038384422 and press Tab
  33. In the Fax Number, type 7038385035
  34. Click in the Notes text box and type PTN is an investment firm with offices in VA, MD, and NY and is interested in network technology for its future activities
     
  35. Click the Projects button. This opens the form allowing to process projects related to this client
  36. In the Project Name text box, type PTNC01
  37. Click the arrow of the Project Manager combo box and select Phillips, David
  38. Click in the Client PO# text box and type 1
  39. In the Project Description text box, type PTN has contracted us, for one year, to provide part-time technical support for its existing computer network. We will be in their office every Wednesday all day long
  40. In the Est. Total Billings text box, type 16250 and press Tab 
  41. In the Project Begin Date, type 031898 and press Tab 
  42. In the Project End Date, type 031899
     
  43. To close the form, click its Close button 
  44. On the Clients form, click the Time Cards button
  45. Click the arrow of the Employee combo box and select Phillips, David 
  46. Select the date in the Date Entered text box, type 03/18/98 and press Tab. 
  47. In the Date Worked text box, type 031898 and press Tab. 
  48. Click the arrow of the Project combo box, select PTNC01 and press Tab. 
  49. Click the arrow of the Work Code combo box, select Regular and press Tab twice. 
  50. In the Billable Hours field, type 8 
  51. In the Work Description field, type Besides regular work, we replaced 2 network cards on the receptionist and Ms. Maureen's workstations
  52. Press Tab to move to the next record of the subform
  53. For the next record, set the Date Worked to 032598 for the PTNC01 project on Regular work billable for 6 hours. For the Work Description, type Spent some time training employee on mild issues of computer networking.
  54. In the Expense subform, click the Date field
  55. Enter 031898 and press Enter
  56. On the Project combo box, select PTNC01 and press Enter
  57. Click the Expense Code combo box and select Computer Supplies
  58. Click the Amount field and type 386.10 
  59. Click the Description field and type I bought 5 network cards. Two were used right away. The spares are kept just in case
  60. Click the Next Record button 
  61. On the Employee combo box, select Nice, Helene
  62. Replace the Date Entered with 032598 
  63. In the Time Worked combo box, click the 1st empty field and type 03/25/98 
  64. Select the Project Name as PTNC01 
  65. Set the Work Code to Regular. Set the Billable Hours to 6 
  66. In the Work Description, type We spent a couple of hours on site with Mr. Phillips. 
  67. To close the form, click its Close button 
  68. On the Clients form, click the Payments button
  69. Click the arrow of the Payment Method combo box, select Check and press Tab
  70. In the Payment Date, type 03/04/98 and press Tab
  71. In the Payment Amount text box, type 8600 and press Tab 
  72. To close the Payments form, click its Close button 
  73. On the Clients form, click Projects to review its form
     
  74. Close the Projects form.

 

Form Printing

 

 

Although not part of their primary role, forms provide a quick means of printing data, especially in the absence of desired reports. There are various issues related to printing forms, including printing all records or just some of them.

 

You can print a form without opening it. Once you know the form you would like to print, locate its name in the Database Window, right-click it and click Print... All records on the form would be printed.

When a form is opened, you have the option of printing all of its records or the selected one. Once in Form View, you can click the Print button on the toolbar. To print just one record, navigate to the record you would like to print, click the Form Selection bar to select the record. On the Form View toolbar, click the Print button.

 

Practical Learning: Printing Forms

 

 

  1. The Clients form should still be opened.
    Click the Projects button to open the associated projects. Since we have only one project from this client, we will just print that record
  2. On the Form View toolbar, click the Print button . Notice that the job goes straight to the printer and starts printing
  3. Close the Projects form and close the Clients form
  4. On the Database Window, double-click Employees 
  5. To navigate to the 3rd employee, click the Next Record button twice
  6. After making sure that the desired record is displaying, in this case, the 3rd record, on the main menu, click File -> Print…
  7. On the Print dialog box, click the Selected Record(s) radio button
  8. Click OK
  9. Verify that only the displaying employee's record was printed
  10. Now we will print records from 2 to 4
  11. Navigate to record No.2
  12. Click the Record Selector bar
     
  13. Press and hold Shift. Click the Next Record button twice to display the record of Lester Vaughn (even though the record # still displays 2)
  14. Release Shift
  15. On the main menu, click File -> Print… 
  16. On the Print dialog box, click the Selected Record(s) radio button and click OK
  17. Verify that records from 2 to 4 have been printed
  18. Close the Employees form

 

 

Reports Fundamentals

 

 

 

AutoReport

 

A report provides an object used to print a database records. Although you can print tables, queries, or forms, reports are customized to be printer friendly. They can perform and display calculations. Once again, Microsoft Access provides wizards to quickly create reports.

The simplest way to create a report is by using the AutoReport feature available either from the New Object button on the Database toolbar or the New Report dialog box.

Practical Learning: Using AutoReport

 

  1. The Rockville Techno database should still be opened
    On the Database Window, click the Tables button
  2. Click the Payment Methods table to select it
  3. On the Database toolbar, click the arrow of the New Object button and select AutoReport
     
  4. After viewing the newly created report, close it
  5. When asked whether you want to save the report, click Yes
  6. Accept the suggested name for the report and press Enter
  7. On the menu bar, click Insert -> Report
  8. On the New Report dialog box, select AutoReport: Columnar
  9. In the combo box, select Expense Codes
     
  10. Click OK
  11. After viewing the report, close it
  12. When asking to save it, click Yes
  13. Accept the suggested name for the report and click OK 

 

 

The Report Wizard

 

 

Microsoft Access can help you create a more elaborate report where you would use one of the pre-designed layouts. This is done using the Report Wizard. The Report Wizard is available from the New Report dialog box that you can access either from the menu bar or from the New button on the Database Window when in the Reports section. If you are using Microsoft Access 2000 or 2002, you can also double-click Create Report By Using Wizard.

 

Practical Learning: Using the Report Wizard

 

 

  1. On the main menu, click Insert -> Report
  2. On the New Report dialog box, click Report Wizard and click OK
  3. On the first page of the wizard, click the arrow of the Tables/Queries combo box and select Table: Employees
  4. Click the Select All Fields button 
  5. Click Next
  6. Accept anything in the second page and click Next
  7. Accept anything in the third page and click Next
  8. In the Layout section, click the Columnar radio button:
     
  9. Click Next
  10. Select the Bold Style to preview it. Then click Formal and click Next
  11. Accept the suggested Title of the report as Employees and press Enter
  12. Scroll down in the report to view the records and close the report

 

Report Printing

 

 

As stated already, the report is the favorite object used to print data. As done with the other objects, you can print a report whether it is opened or not. Before printing a report, you must first select or open it. If you want to print a report without opening it, in the Database window, make sure the Reports section is selected. Then, you can locate and right-click the desired report. If you follow this approach, the report would be sent directly to the printer.

If you want to control or customize the printing of a report, first select it in the Reports section of the Database window or open it. Then, on the main menu, you can click File -> Print… This would display the Print dialog box, allowing you to select a printer if you have more than one. You can also specify such aspects as the color, the number of copies or the range of records to be printed.

 

Practical Learning: Printing a Report

 

 

  1. On the Database window, click the Reports button
  2. Right-click the Expense Codes reports and click Print…
  3. To print a report after displaying it, double-click the Time Sheet report to open it
     
  4. On the main menu, click File -> Print…
  5. Click the Properties button
  6. Based on your printer, make it print in black and white or grayscale and click OK
  7. Click OK on the Print dialog box
  8. After printing the report, close it
  9. On the Database window, click the Forms button and double-click Clients
  10. From the Clients form, click Time Cards
  11. After viewing the Time Cards form, click its Preview Time Card… button
  12. To print the report, on the Print Preview toolbar, click the Print button
  13. After printing the report, close it

 

MOUS Topics

 

 

S6 

Print database objects (..., forms, reports, ...)

S7

Navigate through records in a form

S16

Create a form with the Form Wizard

S23

Enter records using a form

S35

Create a report with the Report Wizard

S26

Preview and print a report

 

Exercises 

 

 

Tenley Associates Company Expenses

 

 

  1. Open the Tenley Associates database
  2. Use the Form Wizard to create a Columnar form based on the Employees table and including all fields. Save the form as Employees and set its display Style to Stone
  3. Use AutoForm: Columnar from the New Form dialog box to create a form based on the Expense Details table and save it as Expense Details
  4. Fill the Employees form up with the following values, ignoring those not mentioned:
     

Last Name

Department

Work Phone

Extension

Bidds

Accounting

(202) 266-5022

2422

Roberts

Sales

(202) 266-5022

2408

Hoaks

Sales

(202) 266-5022

2412

Baugh

Administration

(202) 266-5022

2418

  1. Print the Employees form
  2. Using the Report Wizard, create a Columnar report based on the Expense Categories table, including all fields and using the Corporate style. Save the report as
    Expense Categories and print all of its records
  3. Using the AutoReport from the Database toolbar, create a report based on the Employees Contact Information query. Save the report as
    Employees Contact Information and print all of its records

 

4.

Database Fields on Sheet

 

 

 

Introduction to Data Fields

 

 

A Database From Scratch

 

 

A Database From Scratch

Starting a database from scratch allows you to create and add its different parts as needed. When using this process, the main advantage is that you will exercise as much control as possible on your database because you will be creating all of your objects. The disadvantage is that you will miss that primary layout that the Database Wizard offers. Creating a database from scratch simply means starting from a blank database and adding the different components. Of course, after learning how to perform some changes, you will be able to modify some aspects of a database created using the Database Wizard.

 

To create a database from scratch, if you are just launching Microsoft Access, you can select the first radio button. If you had started Microsoft Access already, you can display the New dialog box and, from the General tab, select Database. Creating a database from scratch also means that you create a database file that does not contain any objects. Therefore, the most you must first do is to give this file a name.

 

Practical Learning: Creating a Blank Database

 

 

  1. To start a new database, on the main menu, click File -> New…
  2. From the New dialog box, click the General tab. Then click the Database icon (in Microsoft Access 97, that will be Blank Database)
     
  3. Then click OK
  4. Since Microsoft Access is going to create a file to store the necessary components of your database, it requires a name
    Change the name of the file to Red Oak High School
  5. Locate the Exercises folder and display it in the Save combo box
  6. Click Create to create the new database file.

 

 

 

Database Object and Fields

 

 

A field is an object used to host, hold, or store a piece of information of a database. Before such an object can perform its function, it must first be created. In the strict sense, the most important or the most regularly used fields of a database are created on a table; but as we have mentioned in previous sections, tables may not be the friendliest windows to present to a user for data entry. For this reason, fields can and should also be created on other windows.

The process of making a field available depends on the type of object it will reside on and probably how the field will be used. This leads to two categories of fields: those that can receive or store information and those that can only present or display it. All fields of a table, especially in Microsoft Access, are created to store data. On the other hand, fields on almost all of the other objects (queries, forms, reports) can be made of combinations of already existing fields of a table, or they can be created independently of any existing or non-existing data.

 

The Table Data Sheet and its Fields

 

 

Table Layout

 

 

To make fields available on a table, you must create each one of them. Before adding the fields, you must first create the table. There are various techniques available. We have already seen how to use the Table Wizard to create a table. Another technique consists of displaying the table as if you were doing data entering. In this Datasheet View, you can create, add, or insert a field. You can also add fields to a table that was created using the Table Wizard. The last technique you can use consists of designing the table.

 

To create a table in Datasheet View, on the Database window, you can click the Tables button and double-click the Create Table By Entering Data. Alternatively, on the toolbar of the Database window, you can click the New button. You can also click Insert -> Table from the main menu. One of these techniques would display the New Table dialog box from which you can click Datasheet View and click OK..

 

Practical Learning: Viewing a Table in Datasheet View

 

 

  1. To create a new database, on the main menu, click File -> New… (or File -> New Database… for Microsoft Access 97)
     
  2. In the New dialog box, click General if necessary. Make sure Database or Blank Database is selected and click OK
  3. Change the name of the file to Clarksville Ice Cream
  4. Locate then display the Exercises folder in the Save In combo box and click Create
  5. To create a new table, on the main menu, click Insert -> Table
     
  6. On the New Table dialog box, make sure Datasheet View is selected and click OK

 

The Title Bar

 

 

A table is a rectangular window. On top, it presents a title bar. The title bar is made of a table's icon . The table icon provides a menu that allows you to minimize, maximize, restore or close the table. The middle section of the table icon is formally called the title bar. Like most regular popup windows, the right section of the title bar presents the system buttons.

 

Columns and Rows

 

 

Imagine you create a list of people with whom you have some type of relationship. The list can be started with names as follows: Bill, James, Hermine, and Khan. This type of list is considered one-dimensional because all of its items fit in one category. In order to create a more significant list, you may want to include these people’s email addresses and probably other related information. If you include these additional pieces of information in the same category, the list may become confusing. To arrange the list, you would create categories. Here is an example:

 

 

Name

Email Address

Phone Number

Relationship

Bill

bill@yahoo.com

 

Friend

James

jamesemail.com

(102)399-2893

 

Hermine

 

(101) 447-8384

Cousin

Khan

@Khan.com

 

 

This type of display allows you to refer to a piece of information by its category. This is the basis of a table. A table is a two-dimensional list of items so that the items are arranged by categories. A complete or incomplete series of items that represent each category is called a record. Therefore, a table can be represented as follows:

In the world of database development, a category is represented as a column. Sometimes it is also called a field. A record is represented as a row. To better organize its information, each column of a table must have a (unique) name. By default, Microsoft Access creates a table with columns named Field1, Field2, Field3, etc. By default, a table starts with 10 columns. You can add more or delete unneeded ones.

By default, a table starts with 21 rows. The number of rows increases as a user adds records. The number of rows decreases if you delete records. As we will learn latter, deleting a row is completely different from deleting a column. 

 

Table Cells

 

 

Although a table is primarily recognized as an arranged list of columns and rows, these are hardly important to the user. Each column and each row intersect to create a rectangular box called a cell. The cell is actually the object that holds data of a table. A cell holds only one piece of information. The database developer decides what type of information would go into a cell:

 

 

The Scroll Bars

 

 

If you start entering data into a table and there are more records than the height of the table can display, the table would be equipped with a vertical scroll bar. The vertical scroll bar would allow you to move up and down on the datasheet. This is useful if/when a table has more records than can be displayed all at once, and this will happen (almost) all the time. In the same way, if a table contains one or more records than the width of the table can display, the table would be equipped with a horizontal scroll bar:

The presence or absence of one or both scroll bars is automatically managed by the operating system. Since you will usually not give your users access to tables, you should not be concerned with the management of scroll bars. If your users need to use a table, they know how to use a scroll bar.

 

Table Navigation Buttons

 

 

The lower left side of the table is made of five buttons used to navigate the table or create records, and a text box. Each button plays a specific picture:

 

Object

Role

First Record: allows moving to the first record of the table

Previous Record: allows to move one record back (if there is one) from the current record

Record Indicator: Displays the number representing the current record

Next Record: allows moving you one record ahead

Last Record: Allows moving you to the last record of the table

New Record: Used to enter a new record on the table

 

 

Table Creation in Datasheet View

 

 

Fields Names

 

 

Once a table displays in Datasheet View, you can simply start entering data into its cells but because the columns would have insignificant names, you should make sure they display names that can identify their type of information.

A field can have almost any name: "Book Title", "This Is The Book Title", "My Book Titles", etc. Some of your fields will have only tinny data, like a person's age, the number of books in an office, a person’s middle initial, etc, it might not be a good idea to give them a name that would take too much space. In the future, when you start programming, it would be easier to handle field names that are composed of only one word, without an empty space.

 

To name a field, first figure out what the data in the category will be made of. If you are planning to enter employees' salaries in a field, you can just call the field Salary. If you want to specify employees’ names by first name, middle name, and last name, you can use such field names and make them distinct. In this case, you could name the first field as firstname (in one word), the last name would be called lastname. Although this good technique allows you to use one word name, some people including yourself might be confused. The suggestion is to distinguish wherever a new English 

 

(or the language you are using to design your database) name starts in the field name, by using a starting uppercase. Instead of firstname, you can use FirstName. Instead of fullname, you can use FullName. Instead of firstdayofmonth, you can use FirstDayOfMonth.

To change the name of a field, you can click its column header, such as Field1. You can also right-click a column and click Rename Column. Alternatively, when any cell under a column has focus, on the main menu, you can click Format -> Rename Column and type the new desired name.

 

Practical Learning: Naming Datasheet Fields

 

 

  1. Double-click the header of the first field: Field1. When it is highlighted, type OrderDate and press Enter
     
  2. Click anywhere under the Field2 column to activate it
  3. On the menu bar, click Format -> Rename Column. That puts the field name in edit mode
  4. Type OrderTime
  5. Right-click Field3 and click Rename Column from the context menu
  6. Type Container and press Tab
     

 

The Name of a Table

 

 

Like everything that is part of a database, a table must have a name that can be used to refer to the object throughout the database in other files that can be linked to the table. Fortunately, when you perform data entry, information you type into a table is saved immediately, as soon as you move to another cell. There are two main ways you can specify the name of a table, either when you save it for the first time or if you decide to rename it.

To save a table you have just created, on the main menu, you can click File -> Save. You can also press Ctrl + S. You could also perform a trick by trying to close the table. You would be prompted to save the table (if its structure has been changed from the structure it had before it was opened).

If a table has not been saved before, you will be asked to provide a name for the table. A table can have any name. With the same concerns we had when creating field names. This time also, there are suggestions made to you. First, the name of a table should reflect the kind of data it is holding. Second, you can name a table with a few words, with spaces; but for the same reasons mentioned earlier, keep the name of a table in one word. The last suggestion sometimes states that you use a prefix that identifies the table as such, a table. The name of a table would be preceded with tbl. If the name includes one word, such as Musicians, you can give the table a name like tblMusicians, another name would be tblStudents. If the name of the table reflects a combination of words, such as Bank Accounts or Students Academic Numbers, start each new word with an uppercase. Here are examples: tblBankAccounts, tblStudentAcademicNumbers, tblMemberRegistrations.

 

Unlike the previous version of this site, we will not use the convention of prefixing the name of a database object with a three letters. For example, the names of tables will not start with tbl. We came to this decision because most other database environments, including Microsoft SQL Server, do not suggest this rule. Although the lack of this rule may create some confusion, because you will end up having a table and a form with the same name, we will strive to explicitly state what object type we are referring to. For example, we will avoid writing, “Open Employees” or “Open the Employees object”. Instead, we will usually state, “Open the Employees table”. This should clearly indicate that you must first click the Tables button in the Database Window because the tables are only in the Tables section, and then open the indicated table. In the same way, if we write, “Open the Employees form”, you must first click the Forms button in Database Window, then open the indicated form.

 

Practical Learning: Saving a Table

 

 

  1. On the Table Datasheet toolbar, click the Save button to save the current table
  2. Type CustomersOrders and press Enter
  3. You will receive a long message box. Click No
  4. To close the table, click its system Close button

 

4b.

Table Creation in Datasheet View

 

 

 

Fields Names

 

Once a table displays in Datasheet View, you can simply start entering data into its cells but because the columns would have insignificant names, you should make sure they display names that can identify their type of information.

A field can have almost any name: "Book Title", "This Is The Book Title", "My Book Titles", etc. Some of your fields will have only tinny data, like a person's age, the number of books in an office, a person’s middle initial, etc, it might not be a good idea to give them a name that would take too much space. In the future, when you start programming, it would be easier to handle field names that are composed of only one word, without an empty space.

To name a field, first figure out what the data in the category will be made of. If you are planning to enter employees' salaries in a field, you can just call the field Salary. If you want to specify employees’ names by first name, middle name, and last name, you can use such field names and make them distinct. In this case, you could name the first field as firstname (in one word), the last name would be called lastname. Although this good technique allows you to use one word name, some people including yourself might be confused. The suggestion is to distinguish wherever a new English 

(or the language you are using to design your database) name starts in the field name, by using a starting uppercase. Instead of firstname, you can use FirstName. Instead of fullname, you can use FullName. Instead of firstdayofmonth, you can use FirstDayOfMonth.

To change the name of a field, you can click its column header, such as Field1. You can also right-click a column and click Rename Column. Alternatively, when any cell under a column has focus, on the main menu, you can click Format -> Rename Column and type the new desired name.

Practical Learning: Naming Datasheet Fields

 

  1. Double-click the header of the first field: Field1. When it is highlighted, type OrderDate and press Enter
     
  2. Click anywhere under the Field2 column to activate it
  3. On the menu bar, click Format -> Rename Column. That puts the field name in edit mode
  4. Type OrderTime
  5. Right-click Field3 and click Rename Column from the context menu
  6. Type Container and press Tab
     

 

 

 

The Name of a Table

 

 

Like everything that is part of a database, a table must have a name that can be used to refer to the object throughout the database in other files that can be linked to the table. Fortunately, when you perform data entry, information you type into a table is saved immediately, as soon as you move to another cell. There are two main ways you can specify the name of a table, either when you save it for the first time or if you decide to rename it.

To save a table you have just created, on the main menu, you can click File -> Save. You can also press Ctrl + S. You could also perform a trick by trying to close the table. You would be prompted to save the table (if its structure has been changed from the structure it had before it was opened).

If a table has not been saved before, you will be asked to provide a name for the table. A table can have any name. With the same concerns we had when creating field names. This time also, there are suggestions made to you. First, the name of a table should reflect the kind of data it is holding. Second, you can name a table with a few words, with spaces; but for the same reasons mentioned earlier, keep the name of a table in one word. The last suggestion sometimes states that you use a prefix that identifies the table as such, a table. The name of a table would be preceded with tbl. If the name includes one word, such as Musicians, you can give the table a name like tblMusicians, another name would be tblStudents. If the name of the table reflects a combination of words, such as Bank Accounts or Students Academic Numbers, start each new word with an uppercase. Here are examples: tblBankAccounts, tblStudentAcademicNumbers, tblMemberRegistrations.

 

Unlike the previous version of this site, we will not use the convention of prefixing the name of a database object with a three letters. For example, the names of tables will not start with tbl. We came to this decision because most other database environments, including Microsoft SQL Server, do not suggest this rule. Although the lack of this rule may create some confusion, because you will end up having a table and a form with the same name, we will strive to explicitly state what object type we are referring to. For example, we will avoid writing, “Open Employees” or “Open the Employees object”. Instead, we will usually state, “Open the Employees table”. This should clearly indicate that you must first click the Tables button in the Database Window because the tables are only in the Tables section, and then open the indicated table. In the same way, if we write, “Open the Employees form”, you must first click the Forms button in Database Window, then open the indicated form.

 

Practical Learning: Saving a Table

 

 

  1. On the Table Datasheet toolbar, click the Save button to save the current table
  2. Type CustomersOrders and press Enter
  3. You will receive a long message box. Click No
  4. To close the table, click its system Close button

 

4c.

Column and Row Maintenance in Datasheet View

 

 

 

Introduction

 

 

A database table and its fields are made of special properties that govern how a table displays its data and how the fields behave. Most of these features are highly customizable. The most important properties you will need to know from a table can help you decide what fields a table should display and in what sequence. Although users will usually not have access to your tables, you should still be aware of some of the internal configurations of a table so you would know what they can do on tables. Anticipating some of the features you will need to implement when designing tables, such as hiding and displaying items, freezing and unfreezing them, it is a good idea to know how these features operate on a table.

 

Column Insertion

 

 

One of the jobs performed when maintaining or improving a table consists of adding new and necessary columns that were not previously available. This can be done in various ways. In the Datasheet View of a table, you can only insert a column in the middle of two existing columns or you can insert a new column to the beginning, that is, to the left of the first column. You cannot simply add a new column at the end of, that is, after the most right column of, the table.

 

To add, that is, to insert a new column, you can right-click the column header that will succeed the new column and click Insert Column. Alternatively, if the caret is positioned in any cell under the column that will succeed it, on the main menu, you can click Insert -> Column.

 

Practical Learning: Inserting a Column

 

 

  1. The Clarksville Ice Cream database should still be opened and the Tables button should be selected in the Database window
    On the Database window, double-click the CustomersOrders table to open it
  2. To add a new field, right-click the OrderDate column header and click Insert Column
  3. Right-click the new Field1 column header and click Rename Column
  4. Type Clerk and click the cell under Container
  5. To insert another column, while the Container column has focus, on the main menu, click Insert -> Column
  6. While the caret is under Field1, on the main menu, click Format -> Rename Column
  7. Type Flavor and press Enter
  8. Enter the following records in the table:
     

Clerk

OrderDate

OrderTime

Flavor

Container

Paulette McIntyre

05/10/2000

10:16 AM

Vanilla

Cup

Ralph Ammian

05/10/2000

10:28 AM

Chocolate Cream

Bowl

Alex Mendy

 

11:35 AM

Butter Pecan

Cone

Ralph Ammian

05/10/2000

 

Vanilla

Cone

  1. Close the table

 

 

Column Selection

 

 

Many times during design or once users have started using your database, you will find that a sequence of fields is not appropriate. In order to move fields, you should know how to select them:

  • To select a column, click the desired column header and release your mouse
  • To select more than one column, click and hold your mouse on one of them, then drag to cover the other desired column or columns, when all desired columns are highlighted, release the mouse
  • To select more than one column, click one column that will be at one end, press and hold Shift, and then click the column that will be at the other end

 

Practical Learning: Selecting Columns

 

 

  1. Right-click the CustomersOrders table and click Open
  2. To select a column, position the mouse on OrderTime until the mouse cursor turns into a down-pointing arrow
     
  3. Then click
     
  4. Notice that the whole column has been selected
  5. To select columns in a range, click and hold the mouse on Container
  6. Then drag left until you get to OrderTime
     
  7. Then release the mouse
  8. To use another technique of selecting columns, click Flavor
  9. Press and hold Shift
  10. Then click Clerk and release Shift
  11. Close the table

 

Column Deletion

 

 

After creating a column, if you find out that you do not need it anymore, you can delete it.

 

If you had created a relationship that the column is involved in, you cannot delete it until you “break” or delete the relationship first.

 

To get rid of a column you do not need anymore, you can right-click it and click Delete Column.

 

Practical Learning: Deleting Columns

 

 

  1. Double-click the CustomersOrders table to open it
  2. Right-click OrderTime and, from the context menu, click Delete Column
  3. When a message box displays, read it and click Yes
  4. Close the table

 

Column Moving

 

 

If you find out during design, data entry, or database maintenance that a particular field is misplaced, you will likely want to move it for better navigation or to ease data entry.

To move a column or group of columns in Datasheet View, first select that column or those columns. Click and hold your mouse on it (or one of them). Then, start dragging left or right in the desired direction. While your mouse is moving, a thick vertical line will guide you. Once the vertical line is positioned to the desired location, release the mouse.

 

Practical Learning: Moving a Column

 

 

  1. Open the ROSH database and, on the Database window, click the Tables button. Open the Staff table in Datasheet View
  2. Scroll right or left so you can see the Sate and the ZIPCode fields at the same time
  3. To move a field, position the mouse on the ZIPCode column header until the mouse cursor turns into a down-pointing arrow:
     
  4. Click to select the whole column (that means click once and release the mouse)
  5. Click the selected column header again and hold the mouse down.
  6. Drag in the left direction until the guiding vertical line is positioned between State and HomePhone:
     
  7. Then release the mouse. Notice that the ZIPCode column has moved
  8. Make sure you can see the HomePhone, the WorkPhone, and the MaritalStatus fields.
    To select two fields, position the mouse on HomePhone. With the mouse cursor pointing down, click and drag in the right direction until WorkPhone is selected, then release the mouse.
  9. Click one of the selected column headers and hold your mouse down
  10. Drag in the right direction until the guiding vertical line is positioned on the right side of MaritalStatus
  11. Then release the mouse
  12. To select a group of columns, click the MaritalStatus column header to select it
  13. Press and hold Shift, then click the WorkPhone column header and release Shift
  14. Click one of the selected column headers and hold your mouse down.
  15. Drag in the left direction until the guiding vertical line is positioned to the left of Extension:
     
  16. Then release the mouse
  17. Save and close the table

 

Record Selection

 

 

To select a row or record in Datasheet View, click the desired row header and release your mouse. To select more than one record, click and hold your mouse on one of them, then drag to cover the other desired row or rows. When all desired rows are highlighted, release the mouse. Another technique used to select more than one row consists of clicking one row that will be at one end, press and hold Shift, and then click the row that will be at the other end.

 

Practical Learning: Selecting Records

 

 

  1. Open the Clarksville Ice Cream database (it should still be in the list of Most Recently Used files under the File menu category)
  2. Double-click the CustomersOrders table to open it
  3. To select one record, position the mouse on the gray button to the left of the third record until the mouse turns into a right pointing arrow
     
  4. Then click
  5. Notice that all cells of the second records are highlighted
  6. To select a range of records, click the gray button to the left of the fourth record. Then click once
  7. Press and hold Shift. Then click the gray button to the left of the second record, and release Shift
     
  8. Notice that three records have been selected
  9. Close the table

 

Record Deletion

 

 

If a record is not needed anymore or has become irrelevant in a database, you can delete it. To do this, right-click the record selector button, which is the gray box, on the left side of the most left field of the record, and click Delete Record from the context menu.

 

Practical Learning: Deleting Records

 

 

  1. Open the CustomersOrder table
  2. To delete a record, right-click the gray button to the left of the second
     
  3. Click Delete Record
  4. A warning message box will appear. Read it and click Yes
  5. To delete more than one record, click and hold the mouse on the gray button to the left of the second record, then drag down to include the third record in the selection
  6. On your keyboard, press Delete
  7. Read the warning message box and press Enter
  8. To close the table, press Ctrl + F4

 

Columns Width and Rows Height

 

 

The columns and rows of a table use some default values to display their records and fields. When data exceeds the regular width of a column, part of the information would be hidden. If a particular column contains data that you want to display at all times, you can enlarge the column. On the other hand, if a column displays short pieces of information, such as one character for middle initial or two characters (US states or Canadian provinces), you can narrow the column to let it just fit the data as desired. In the same way, you can heighten or shrink rows of a table as you see fit.

 

There are various techniques you can follow to widen or narrow a column. You can position the mouse on the right border of the column header. The mouse pointer would change into a horizontal double arrow crossed by a vertical beam. If you double-click, the column would be sized to the widest value of the column, provided the widest value is wider than the column header. If the widest value is narrower than the column header, the column width would be wide enough to display the caption of the column. On the other hand, you can change a column's width by clicking on the column's right border and dragging in the desired direction.

To set or change the rows height, you can position the mouse on one of the rows lower border, then click and drag in the opposite direction.

 

Practical Learning: Changing Columns Width and Rows Height

 

 

  1. Open the Rockville Techno database that you started in Lesson 2 and, in the Database window, click the Tables button
  2. From the Tables section of the Database window, double-click the Employees table to open it
  3. To resize the First Name column, position your mouse on the line between First Name and Last Name until the mouse pointer appears as an I-beam (also called a pipe) with a horizontal double-arrow:
     
  4. Then double-click
  5. To resize the Address column, position your mouse on the line between Address and City:
     
  6. Then click and drag in the right direction until the mouse is positioned in the middle of City:
     
  7. Release the mouse
  8. Right-click the Country column header and click Column Width...
  9. In the Column Width dialog box, type 12.50 to replace the default value
     
  10. Click OK
  11. Click and cell under the Title column
  12. On the main menu, click Format -> Column Width...
  13. On the Column Width dialog box, click Best Fit and click OK
  14. Save and close the table

 

MOUS Topics

 

 

S8

Create a database (... in-design view)

S11

Modify field properties

S25

Delete records from a table

 

Exercises 

 

 

Yugo National Bank

 

 

  1. Create a blank database and name it Yugo National Bank
  2. Using the Table Wizard, create a table based on the Accounts sample table of the Personal category. Include the following fields: AccountTypeID, AccountType, and Description. Save the table as AccountTypes and fill it up as follows:
     

Account Type ID

Account Type

Description

1

Checking

 

2

Saving

 

3

CD

 

  1. Using the Table Wizard, create a table based on the Employees sample table of the Business category. Include the following fields: EmployeeID, DepartmentName, EmployeeNumber, FirstName, LastName, Title, EmailName, WorkPhone, Extension, Address, City, StateOrProvince, PostalCode, Country, HomePhone, Salary, and Notes. Save the table as Employees and fill it up with employees records
  2. Using the Table Wizard, create a table including the CustomerID field from the Customers sample table of the Business category. From the Accounts sample table of the Personal category, include the following fields: AccountNumber, AccountTypeID, AccountName. From the Addresses sample table, include the following fields: Address, City, StateOrProvince, PostalCode, Country, EmailAddress, HomePhone, WorkPhone, WorkExtension, DateUpdated, and Notes. Save the table as Customers and fill it up with sample customers records

 

Watts A loan

 

 

  1. Catherine Watts lives in Baltimore, Maryland, US. Eight months ago, while living with her father, one weekend, she went to attend the wedding of her friend in Chicago. Meanwhile, her father had a heart problem and was rushed to the hospital after a neighbor found him on the floor of his dining room. The attending doctor wrote on a chart that Catherine's father would be kept nightly for further examinations. While her father was still lying in bed in the hallway and sleeping, a nurse came back and from some events that nobody recalls, Mr. Watts' chart was modified. Next, he was taken to a surgery room since his chart  now indicated that he had been in an unrecoverable accident but that he was a happy organ donor. In the next few minutes, his body was cut in various pieces. His right liver was sent to Canada while the other gave new hope to a patient in California. His left eye gave new site to a woman in Mexico and his skin allowed a man who had been in the center of a mass fire a new cover for his body. The rest of his organs were spread in the region like salt in boiling water. When the attending doctor came back to look for his patient, he found out what had happened but it was quite late to undo anything. When Catherine came back from Chicago and was asked to recognize at least what was left of her father, she was furious but calmly considered it was an accident. At her friend's insistence, she sued the hospital and got a five-million-dollar settlement. To make sure she would not spend all that cash picking up men in bars and night clubs, her friend encouraged her to open a business. Since Catherine had taken some classes in banking management, she decided to open a money lending institution. She would lend money to individuals through car dealers, music instrument stores, furniture stores, and personal loans, etc. She has contracted you to create an application that can help her manage her business.
    Create a blank database and name it Watts A Loan
  2. Using the Table Wizard, create a table with the following fields: CustomerID, (and from the Mailing List sample table) FirstName, MiddleName, LastName, Address, City, State, PostalCode (rename it ZIPCode), Country, HomePhone, WorkPhone, EmailAddress, and Notes. Name the table as Customers
  3. Using the Table Wizard, create another table with the following fields: TransactionID, TransactionNumber, TransactionDate, TransactionAmount, and Notes. Save the table as Transactions

 

5.

Managing Data Fields 

 

 

 

Table Design and Fields

 

 

Introduction

 

 

So far, to get acquainted with database fields, we have used two techniques of creating a table and some techniques of adding fields to a form. One of the techniques we used, the Datasheet View, provides a very simplistic way. The Datasheet View is mainly used to perform data entry or to test some fields. It has so many limitations that you will hardly use it. For example, you cannot control or customize the behavior of fields if you create the table in Datasheet View. The other technique we used, the Table Wizard, allows you to use some already created and customized fields. For one thing, you would not know what exactly those fields are configured to do and whether they can control data entered in them. For another thing, if you do not like the way they behave, you would have to modify the configuration that was already done. This is why you should know how to design your tables.

Table Design consists of creating a list of columns, specifying the type of information they can receive, and controlling their behavior. To design a table, you should display it in Design View, which is a display other than Datasheet View. To create a new table in Design View, on the menu bar, you can click Insert -> Table. You can also click the arrow of the New Object button 

 

on the Database toolbar and select Table. As another alternative, you can click the New button on the Database Window's toolbar while in the Tables section. Any of these actions would call the New Table dialog box. In the New Table dialog box, you can click Design View and click OK.

The quickest way to create a table in Design View when using Microsoft Access 2000 and later versions is to double-click the Create Table In Design View link from the Database Window.

 

Practical Learning:  Introducing Table Design

 

 

  1. Open the Clarksville Ice Cream database that you started
  2. In the Database Window, if necessary, click the Tables button
    From the Database Window toolbar, click the New button to create a new table
     
  3. On the New Table dialog box, click Design View and click OK

 

 

The Table in Design view

 

 

The title bar of a table in Design View presents the table’s icon on the left section. Like most other windows, the table's icon holds the table's system menu. This system icon can also be double-clicked to close the table. The long empty section of the title bar is different from a classic window. Instead of being used to maximize, minimize, move, or close the table, it provides features adapted for the database object it is. For example, at a minimum, it can be used to switch views. To use its function, you can right-click it. This would present a menu you can select from:

The right section of the title bar presents the system buttons of a regular window. They can be used to minimize, maximize, restore, or close the table.

On the left side of the view, the row headers allow you to select a row completely. The most left gray button allows you to select everything on the table while in Design View:

The File Name column is used to type a name for each field. The rules we used when in Datasheet View apply here. A field can have any name but keep a name with one word and no space.

 

Practical Learning:  Creating Columns in Design New

 

 

  1. While in Design View, click the first empty box under Field Name, type EmployeeID
  2. Press the Tab key three times and type DateHired 
  3. Press the down arrow key and type EmployeeNumber 
  4. Press the down arrow key and type FirstName 
  5. Press the down arrow key and type MiddleInitial 
  6. Press the down arrow key and type LastName 
  7. Press the down arrow key and type WorkPhone 
  8. Press the down arrow key and type Extension 
  9. Press the down arrow key and type EmailAddress 
  10. Press the down arrow key and type Address 
  11. Press the down arrow key and type City 
  12. Press the down arrow key and type State 
  13. Press the down arrow key and type ZIPCode 
  14. Press the down arrow key and type Country 
  15. Press the down arrow key and type Salary 
  16. Press the down arrow key and type MaritalStatus 
  17. Press the down arrow key, type Notes and press Tab
  18. To save the table, on the Table Design toolbar, click the Save button
  19. Change the name of the table to Employees and click OK
     

  1. You will receive a long message box about a lack of a primary key (we are not there yet). Click No
  2. Close the table

 

Field Renaming

 

 

One of the jobs involved with database design and maintenance is to review fields and make sure they are explicit enough for the user. There are three issues related to a field's name. Some fields, as you will find out, are involved in relationships, and you will have to be careful when deciding to change their name. The other issues are related to a field's actual name and its caption.

 

A field's name is mainly made of two parts from the developer's standpoint: the actual name and the caption. A field's name is stored as part of the table and is involved with any business dealing the table has to cope with. The caption simply guides the user in identifying the use of a particular field. These two items are not strictly related. For example, you could have a field whose name is SocSecNbr while its caption displays Nat Number From Gvt and this will not affect the functionality of the table. Overall, as a developer, you should pay attention to your fields names because these are the names you will refer to when performing calculations and other programming issues.

To rename a field in Datasheet View, use any of the techniques we learned to change a field's name. After you have typed the name, the new name will replace the old one. To rename a field in Design View, click it and type the new name.

 

Practical Learning: Renaming a Field

 

 

  1. Open the Rockville Techno database. In the Database window, if necessary, click the Tables button
  2. Double-click the Employees table to open it
  3. Complete the records as follows:
     

First Name 

Last Name 

Title

Extension

Billing Rate

Christine

Barley

Administrative Assistant

106

16.82

Joseph

Kumar

Network Administrator

105

20.65

Joanne

Herbie

Accountant

108

22.48

  1. To switch the table to Design View, right-click its title bar and click Table Design
  2. In StateOrProvince, click between the most left e and O. Then press and hold Delete until the Field Name displays State
  3. Press the down arrow key to select PostalCode and type ZIPCode
  4. Double-click EmailName, type EmailAddress and press Tab
  5. Save the table and close it

 

Field Selection in Table Design View

 

 

In the Design View of a table, there are various types of operations you can perform for database maintenance. Operations include naming or renaming fields, moving or deleting fields, and changing various other properties. In order to perform some of the operations on a field or a group of fields, you must first select one.

  • To select one field, you can position the mouse on the gray box to its left and click
  • To select more than one column, you can click and hold your mouse on one of the left gray boxes, then drag up or down to cover the other desired field names. When all desired field names are highlighted, release the mouse
  • To select more than one column, you can also click one column that will be at one end, press and hold Shift, then click the column that will be at the other end
  • To select columns at random, click the left gray box of one of them, press and hold Ctrl, then click the gray box of each of the desired boxes

 

Column Moving in Table Design View

 

 

The columns of a table are displayed in the sequence in which they were created. We learned earlier how to change this sequence in Datasheet View. You can also change the sequence of fields in the Design View of a table.

  • To move a column or a group of columns, after making the selection, click the gray box of the field name or one of the gray boxes of one of the selected fields and hold the mouse down. Then drag up or down. A horizontal line will guide you. Once it gets to the desired location, you can release the mouse

 

Practical Learning: Maintaining Fields in Table Design View

 

 

  1. The Rockville Techno database should still be opened.
    To open the Employees table in Design View, in the Tables section of the Database window, right-click the Employees table and click Design
  2. While in the Design View of the table, click the gray box on the left of Extension to select it
     
  3. Click the same box again and hold the mouse down. Then drag it down until the guiding horizontal line is positioned under WorkPhone
     
  4. Release the mouse
  5. To select various fields, position the mouse pointer to the left gray box of the HomePhone field until the mouse pointer changes into a right pointing arrow:
     
  6. Click and hold the mouse down. While holding, drag down to Extension to select those 3 fields, and release the mouse
  7. To move the selected fields, click and hold the mouse on one of the black selected boxes on the left of the field names
  8. Drag up until the guiding horizontal line is positioned on top of Title:
     
  9. Then release the mouse
  10. Save and close the table

 

Field Insertion

 

 

When it comes to tables, the best place to add new fields is in Design View because this view provides more flexibility. In Design View, you can insert a new field at any position. You can also add a new field to the end of the table, a feature that is not available in Datasheet View. You can also use one of the same fields as we saw when using the Table Wizard:

  • To insert a new column, you can right-click the field that will succeed it (you can right-click anywhere on the horizontal boxes of the column, that is, on the Field Name, the Data Type, or the Description columns), click Insert Rows, and type a name for the new column
  • To insert a new column, you can also click anywhere on the column that will succeed it. Then, on the main menu, click Insert -> Rows. Alternatively, when a column has focus, on the Table Design toolbar, you can also click the Insert Rows button
  • To add a new column at the end of the table, click the first empty field under Field Name and type the desired name
  • To use one of the fields available from the Table Wizard, right-click either the first empty field under Field Name or right-click the field that will succeed it and click Build… On the Field Builder dialog box, select the category (Business or Personal), select the desired field, and then click OK

 

Practical Learning: Inserting New Fields in Table Design View

 

 

  1. The Rockville Techno database should still be opened.
    To open the Employees table in Design View, in the Database window, click it to select it if necessary. Then, on the Database window, click the Design button
  2. To add a new field at the end of the table, click the first empty box under BillingRate. Type Observations and press Enter
  3. To insert a new field before LastName, right-click LastName and click Insert Rows
  4. Type MiddleName and press Tab
  5. To insert an already configured field, right-click EmployeeNumber and click Build…
  6. In the Field Builder, click the Business radio button if necessary. In the Sample Tables list, click Employees
  7. In the Sample fields list, scroll down and click DateHired
     
  8. Click OK
  9. To add another field, click Address
  10. On the main menu, click Insert -> Rows
  11. Type WebSite and press Enter
  12. Save the table

 

Field Deletion

 

 

When in Design View, you can delete a field you don't need anymore or if it was added by mistake. To delete a column, you can right-click anywhere on its line (on the Field Name, the Data Type, or the Description columns) and click Delete Rows. When a column has focus, you can also click the Delete Rows button on the Table Design toolbar to delete it.

 

Practical Learning: Deleting a Field in Table Design View

 

 

  1. To get rid of a column, right-click WebSite and click Delete Rows
  2. When asked whether you want to permanently delete the field(s), click Yes
  3. Save and close the table

 

5b.

Queries and Fields

 

 

 

Introduction

 

 

We previously learned that fields could be easily added to a query by using the Query Wizard. Fields can also be added while designing a query. To proceed with this approach, the query should be displayed in Design View.

To display a query in Design View, if you are using Microsoft Access 2000, from the Queries section of the Database Window, you can double-click Create Query in Design View. Alternatively, do one of the following:

 

  • On the Queries section of the Database Window, you can click the New button
  • On the main menu, you can click Insert -> Query
  • On the Database toolbar, you can click the arrow of the New Object button and select Query 

Any of these techniques would call the New Query dialog box where Design View is selected by default. Otherwise you can select Design View and click OK.

To start a fresh query, the database needs to know where data would come from. Therefore, the Design View displays a list of already existing tables and queries so you can choose which one(s) would provide the needed information:

A simple query can have its data originate from a single table. Therefore, to choose the table that holds the information needed for this query, you can click that table and click Add. You can also double-click it. A simple query can also be built from an existing query. To use such a query, in the Database window, click the Queries button and select the query you want. You can also create a query whose data would originate from more than one table. In this case, the tables must have been previously joined. To select the tables, from the Tables property page of the Show Table dialog box, you can double-click each one of the tables you need. More advanced queries can be built from more than two queries, a table and a query, or a combination of tables and queries.

After selecting the table, tables, query, or queries, you can click the Close button of the Show Tables dialog box. If the Show Tables dialog box is closed or for any reason and you want to display it, on the menu bar, you can click Query -> Show Table...

 

Practical Learning: Introducing Query Design

 

 

  1. Open Windows Explorer or My Computer. From the resources that accompany this site, copy the Bethesda Car Rental1 database and paste it in your Exercises folder
  2. Open the Bethesda Car Rental1 database and, in the Database Window, click the Tables button
  3. Click the Cars table to select it. Then, on the toolbar of the Database window, click the Open button
  4. Scroll to the right of the table to review the columns
  5. Close the Cars table
  6. On the Database Window, click Queries and click the New button
     
  7. In the New Query dialog box, click Design View and click OK. Notice that you are presented with a list of existing tables
  8. On the Show Table dialog box, click Cars
  9. Click Add and click Close

 

 

Query Design

 

 

The Select Query window presents another classic window. Its title bar displays its system button on the left section. This can be used to minimize, maximize, restore, move, resize, or close the window. Like all Microsoft Access window objects, the title bar displays a special menu when right-clicked:

The right section of the title bar displays the classic system buttons of a regular window.

In the top wide area of the Select Query window, the query displays an object (table(s), query (queries)) or a group of objects that was selected to create the query. The lower portion of the query displays boxes that would be used to perform various operations related to the query. The upper and the lower sections of the Select Query window are separated by a splitter bar that you can use to resize them by dragging the splitter bar up or down:

 

 

Column Insertion

 

 

To create the fields for a query, you use the table, query, tables, or queries displayed in the upper section of the window. Once you have decided on the originating object or objects, you can select which fields are relevant for your query:

  • To select one field from the list, just click it
  • To select many fields on the same range, you can click one of them, press and hold Shift. Then click one field on the other end of the desired list
  • To select fields at random, click one of the desired fields, press and hold Ctrl; then click each one of the desired fields
  • To select all fields, you can either double-click the title bar of the list or click the * line on the list of fields.

Once you have made your selection on the list, you can drag it and drop it on the query. Instead of dragging a field or all fields, you can either double-click a field to add it to the query, or double-click the * line to add all fields to the query.

 

Practical Learning: Select Fields to Build a Query

 

 

  1. From the list of fields, click and drag Make, then drop it anywhere on the first empty field on the lower section of the view:
     
  2. On the list, scroll down and click AMFM
  3. Press and hold Shift, then click CDPlayer and release Shift. Notice that three fields have been selected
  4. Drag the group of items and drop it on the empty column right to Make
     

     
  5. Notice all the selected fields have been added to the query
     
  6. To view the query, on the Query Design toolbar, click the View button
  7. After viewing the query, to save it, on the Query Datasheet toolbar, click the Save button
  8. Type Cars Audio Options as the name of the query and press Enter
  9. After viewing the query, to close it, click its Close button

 

Column Selection

 

 

Sometimes, the idea of using a query is to test data or verify a condition. Therefore, a query, as compared to a table, could provide just a temporary means of studying information on your database. When performing such assignments or when testing values before isolating an appropriate list, you can add, insert, delete, replace or move fields at will. We have already covered different techniques of adding or inserting fields:

  • To select a field in the lower section of the view, click the tinny gray bar of the column header. The whole column will be selected
  • To select a range of columns, click the column header of one at one end, press and hold Shift, then click the column header at the other end

 

Column Replacement and Deletion on a Query

 

 

As seen above, a query is built by selecting columns from the originating list and adding them. If you do not need a column anymore on a query, which happens regularly during data analysis, you can either delete it or replace it with another column:

  • To delete a column, once it is selected, you can press Delete
  • To delete a group of columns, select them and press Delete
  • To replace a column, click the arrow on the combo box that displays its name and select a different field from the list 

 

Column Moving

 

 

Columns on a query are positioned incrementally as they are added to its list. If you don't like the arrangement, you can move them and apply any sequence of your choice. Before moving a column or a group of columns, you must first select it, then:

  • To move a field, click its column header once. Click it again and hold your mouse down, then drag in the direction on your choice
  • To move a group of columns, first select the group and then proceed as if it were one column

 

Practical Learning: Manipulating Fields

 

 

  1. The Bethesda Car Rental1 database should still be opened
    In the Database Window, click the Tables button and click Cars to select it
  2. On the menu bar, click Insert -> Query
  3. In the New Query dialog box, double-click Design View
    Notice that the Cars table is already selected as the originating object
  4. In the list of fields, double-click Make, Model, NbrOfDoors, AMFM, Cassette, and CDPlayer
  5. To view the query, on the Query Design toolbar, click the View button
  6. After viewing the query, to switch back to Design View, on the Query Datasheet toolbar, click the View button 
  7. To replace a field, in the lower section of the Design View, click NbrOfDoors and notice that an arrow of a combo box appears
  8. Click the arrow of the NbrOfDoors combo box and select CarYear
     
  9. Scroll to the right on the lower section of the view to display the first empty field
  10. To add a new field, click CDPlayer and press Tab. Notice the combo box
  11. Press and hold Alt, then press the down arrow key and release Alt. This displays the list of the combo box
  12. Press the down arrow key a few times until Picture is selected, then press Enter
  13. Scroll back to the left
  14. To insert a field, drag TagNumber from the Cars list and drop it on top of AMFM
  15. Notice that the newly inserted field has been added to the left of the field it was dropped on
    (In the same way, you can select various fields and decide to insert them to the left of a field of your choice)
  16. Scroll to the right side of the lower section of the view until you can see Picture.
    To delete a field, in the lower section of the view, position the mouse on the tinny horizontal bar above Picture until the mouse turns into a down pointing arrow:
     
  17. Click. Notice that the whole column is selected
  18. Press Delete. Notice that the field is removed from the query
  19. To view the query, click the View button
  20. To switch the query back to Design View, on the main menu, click View -> Design View
  21. Scroll back to the left of the lower view and make sure you can see the TagNumber and the Make columns
    In the lower section of the view, click the bar on top of TagNumber and release the mouse
  22. Click the TagNumber header bar again and hold your mouse down
  23. Notice a vertical line that guides you. Drag left until the vertical guiding line gets between Make and Model:
     
  24. Release the mouse 
  25. To view the query, on the Query Design toolbar, click the View button
  26. Switch the query back to Design View
  27. Scroll the lower section right to see CDPlayer
  28. Click and hold your mouse on the bar on top of AMFM. Then drag right to CDPlayer to select the AMFM, the Cassette, and the CDPlayer columns. Then release the mouse 
  29. Click and hold your mouse again on the bar on top of AMFM
  30. Drag left until the vertical line is between the Model and the CarYear columns
  31. Then release the mouse
  32. To run the query, right-click its title bar and click Datasheet View 
  33. To close the query, double-click its system icon
  34. A message asks you whether you want to save the query, click No (this was a test; it was just a test…)

 

MOUS Topics

 

 

S2

Create Table Structure

S11

Modify field properties

S13

Modify tables using Design View

 

Exercises 

 

 

Yugo National Bank

 

 

  1. Open the Yugo National Bank database and open the Customers table in Design View. Insert a new field between CustomerID and AccountNumber. Name it DateCreated and close the table
  2. Use the Table Wizard to create a new table based on the Accounts sample table of the Personal category and include only the AccountTypeID field. Rename AccountTypeID as TransactionTypeID. Save the table as TransactionTypes and open it in Design View. Under the existing field, add another field named TransactionType. Using the Field Builder, add a field based on the Notes sample. Rename it Description. Save the table and perform data entry as follows:
     

TransactionTypeID

TransactionType

Description

1

Deposit

Used if a customer is depositing money, regardless of the type of account

2

Withdrawal

Specifies that a customer is receiving money. This also applies when a check is cashed from the customer's account

3

Fund Transfer

This applies to an operation that consists of transferring money from one account to another

4

Money Order

This is selected if a person is purchasing a money order from this bank

5

Service Charge

There are various types of service charges. This category applies to all of them, regardless of the reason, as long as the Bank Management decides to withdraw money from the customer's account as a fee or a penalty

3.      Close the table

 

Watts A Loan

 

 

  1. Open the Watts A Loan database. In the Datasheet View of the Customers table, insert a new field between CustomerID and FirstName. Name it AccountNumber
  2. Using the Table Wizard, create a table with the following fields of the Employees sample table: EmployeeID, DepartmentID , FirstNameLastName, EmailName, Address, City, StateOrProvince, PostalCode, Country, HomePhone, WorkPhone, Salary, and Notes. Name the table Employees and close it
  3. Using the Design View of the Customers table, use the Field Builder dialog box to add a new field at the end of the table (under Notes) and base the field on the OrderDate field from the Orders sample table of the Business category. Rename the field as AccountDate then move it up to position it between CustomerID and AccountNumber. Save and close the table
  4. Open the Employees table in Design View and change the names of the following fields:
     

Field Name

New Name

EmailName

Username

StateOrProvince

State

PostalCode

ZIPCode

Salary

HourlySalary

5.      Save and close the table

 

6.

Database Fields on Forms and Reports

 

 

 

Common Fields of Forms and Reports

 

 

Introduction

 

 

As we saw in previous lessons, fields are created on a table, then they can be added to a query. Based on the way Microsoft Access deals with fields, a field on a table cannot be created as a combination of other fields, as if it were an expression (unless the field is created as “lookup”)(We know that other database environments, including Microsoft SQL Server and MySQL, allow using an expression as the value of a column of a table but MS Access doesn't). Instead, the fields on a table are primarily created to store data. On the other hand, as we will see in the next few lessons, a new field can be added to a query as a combination, through an expression, of other fields. Forms and reports present this same solution. Besides using the fields of a table or a query, a new field can be added to a form or report. This is because forms and reports use objects called Windows controls.

 

Labels

 

 

A label is a static object that presents a word or a group of words. The user cannot (directly) change the value that a label is displaying. By default, a label displays its sentence on a gray background.

 

Text Boxes

 

 

A text box is a rectangular object with a white background and thick borders. On a form, a text box either presents information to the user, requests data from the user, or does both. On a report, a text box is used like a label: to display information that would be printed.

A text box may not be explicit enough to indicate what it is used for. For this reason, it is usually positioned next to a label. The label is usually positioned on top, or to the left, of the text box it is accompanying. For this reason, a text box is named after the label close to it. For example, and throughout this site, if a text box is placed under, or on the right side of, a label that displays First Name, the text box would be called “The First Name Text Box”.

 

Combo Boxes

 

 

A combo box is a type of text box that displays an item selected from a list it is holding. On a form, to change an item in a combo box, you can click its arrow and make your selection from the list. On a report, a combo box appears as such only when in design. When printed, only its data displays. Although it depends on the programmer's configuration of the combo box, the user may not be allowed to enter in a combo box something that is not part of the preset list.

 

 

Navigation Buttons

 

 

Forms and reports are equipped with the same navigation buttons used on tables (and queries). This time, they are used to navigate left and right to the previous or the next records instead of up and down.

Object Role
First Record: allows moving to the first record
Previous Record: allows to move one record back (if there is one) from the current record
Record Indicator: Displays the number representing the current record
Next Record: allows moving one record ahead
Last Record: Allows moving to the last record
New Record: Used to enter a new record

 

 

Object

Role

First Record: allows moving to the first record

Previous Record: allows moving one record back (if there is one) from the current record

Record Indicator: Displays the number representing the current record

Next Record: allows moving one record ahead

Last Record: Allows moving to the last record

New Record: Used to enter a new record for a form
Since you cannot create a new record on a report, this button is not available on it

 

Practical Learning: Reviewing Controls on Forms and Reports

 

 

  1. Start Microsoft Access and open the Rockville Techno database that you started
  2. On the Database window, click the Forms button. Then double-click the Clients form to open it 
  3. On the Clients form, click the Time Cards button
     
  4. Notice the Employee and Date Entered labels
  5. Also notice the Employee combo box
  6. Notice also the Date Entered, the Total Hours, and the Total Expenses text boxes

 

Forms Fields

 

 

Introduction

 

 

Microsoft Access is an MDI application. This means that it allows you to open many objects, such as different forms and/or reports at the same time. This lets you switch from one window to another to perform data entry on related objects.

A form, by design, provides a friendlier interface and should make its navigation easy for the user. To provide this functionality, a form can be equipped with various types of Windows controls. Some of the objects are used only to display information to the user. Some others allow the user to change data.

Subform

 

 

A subform is a form that is “glued” or embedded in another form. It is used to display related data that would otherwise be accessible from another form.

 

Record Selector

 

 

A form is equipped with a special area that allows selecting the currently displaying record. The Record Selector is on the left side immediate to the left border of the form. The Record Selector is not available on all forms. The database developer decides on its availability or not.

 

Practical Learning: Reviewing Controls on Forms

 

 

  1. Notice the Time Worked and the Expenses sub forms
  2. To view the design of subform, right-click the title bar of the Time Cards form and click Form Design
     
  3. After viewing the form, right-click its title bar and click Form View

 

Reports and Controls

 

 

Introduction

 

 

Like a form, a report uses the same label, text box, combo box, and list box controls. As mentioned already, the appearance of the controls may not be printed as we will see when studying properties of controls, the background and borders of controls can be changed for aesthetic reasons. Such background and borders would be printed.

 

Subreport

 

 

A subreport is a report added to a parent report in a master-detail layout. It allows the user to view data from different tables but that is related to create a more realistic report. Although playing the same roles, subforms and subreports are not created the exact same way.

 

Practical Learning: Reviewing Controls on Reports

 

 

  1. On the Time Cards form, click the Preview Time Card button
  2. To view the design of a subreport, on the main menu, click View -> Design View
  3. Notice the Time and Expenses subreports in the Detail section
  4. To preview the report, on the main menu, click View -> Print Preview
     
  5. Close the Time Sheet report
  6. Close the Time Cards form
  7. Close the Clients form

 

6b.

Database Fields on Forms and Reports

 

 

 

Design of Forms and Reports Fields

 

 

Common Field Design on Forms and Reports

 

Forms provide a friendlier look for data entry to the main user of the database. As such, you will spend a great deal of time designing their look, tuning their functionality, and checking their efficiency. Even when creating a product from the Database Wizard, you will usually realize that various objects are lacking critical fields for the role of the object, or the database itself, as software, needs a few more objects.

As we have learned already, the quickest way to create forms and reports is by using the Database Wizard. Even if you create your database from scratch, you still can use the AutoForm or AutoReport to get very easily rendered and readily available objects. As it happens, the Database Wizard was configured to create only a limited number of objects. If you need additional objects, you can create your own. If you want to control everything or almost everything on the forms and reports, you will have to get into design.

To add fields to a form or a report, you must display the object in Design View. This gives you access to the Controls toolbox, which hosts some of the Windows controls used on forms and reports.

Field Insertion on Forms and Reports

 

Data on fields of forms and reports fall in three main categories: fields that directly originate from a table or a query, fields created as a combination of existing fields, and fields independent of any other fields. The techniques used to create these fields are different but a field created using one technique can be changed into another category as necessary.

If you want to use a field that is already part of a table or a query, before, or when, creating the form or report, you must specify the list that holds the fields. There are three main ways you can do this:

  • While in the New Form or the New Report dialog boxes, or if you are using the Form Wizard or the Report Wizard, you can select the object (table or query) that holds the list of fields from the combo box
     

Selecting an object from the New Form's combo box

  • If you have already started a form or a report and it is displaying in Design View but you did not yet select the table or report that holds the list of fields, on the Properties window for the form, you can click the arrow of the Record Source field and select the table or query from the list
  • If you want to use only a selected list of fields from a table or a query, start the form or report in Design View without selecting an object. Then, on the Properties window, click the Record Source field and click its ellipsis button. This will allow you to use the Query Builder to create a query that is a list of the needed field. After creating the query, close it. Its Field List would display only the previously selected fields

To add a field to a form or a report, you can either click a control from the Toolbox and click the form or report, or drag a field from the Field List to the form or report.

 

 

Introduction to Form Design

 

 

When it comes up, a form is presented as a rectangular box made of a form selection button, two rulers, two scroll bars, a horizontal bar labeled Detail, and a gray area:

 

 

By default, a form presents a section referred to as the Detail section. This section starts from the Detail bar to the lower end of the section.

Besides the Detail section, a form can be equipped with additional sections. To add these sections, you can:

  • Right-click the middle of the form and click either Page Header/Footer or Form Header/Footer
  • On the main menu, you can click View and click either either Page Header/Footer or Form Header/Footer

If you click Form Header/Footer after right-clicking the form, two new sections will be added to the form: the Form Header section on top and the Form Footer section at the bottom:

Although two sections are added, you can reduce one completely so it would not appear to the user. Therefore, you can keep one section and hide the other. If you create a form using the Form Wizard, both the header and the footer sections are added but they are completely reduced so they would not appear to the user. If you want to display them to the user, you must expand them.

If you click Page Header/Footer after right-clicking the form, two sections would be added to the form: a Page Header and a Form Header sections. These sections would not appear to the user. They appear only if the user decides to print a form, in which case they would appear on the printed paper. Like the Form sections, you can change either or both the Page Header and the Page Footer sections

To create a field on a form, you can click a control on the Toolbox and click one of the sections. You can also drag a control from the Fields List to a section of the form. Normally, you are allowed to add any control on any section but there are suggestions you should follow:

  • You should add in the Form Header section a control that would display a common message of all records. An example would be the title of the form since the Form Header appears on top of the form. Such a field can be made independent of any other field. In some cases, you can also include an expression that can remind the user of the data on the current record. You can also add a company’s logo to the Form Header so it can display the same for all records
  • The Detail section is the most commonly used section of a form. It can be used to display any control. It is also the favorite place to display the current record of the form. Every form should (in fact must) have a Detail section.
  • As mentioned already, the Page Header and the Page Footer sections do not appear to the user. If you allow the users to print a form, you can add these sections and create fields on them. On the other hand, if you think the users would not print the form or if you prevent this, you can use these sections to add controls that can be used by the form or database but must be hidden from the user (for example, since you cannot declare (VBA) variables in Microsoft Access, you can include pseudo-variables in the Page sections and refer to these pseudo-variables in your expressions; the pseudo-variables can be added like normal controls and their contents would be used as variables: only you are aware of such controls, not the user).

 

Practical Learning: Creating Forms Fields

 

 

  1. The Rockville Techno database should still be opened
    On the Database window, click the Forms button if necessary. Then, on the main menu, click Insert -> Form
     

New Form

  1. On the New Form dialog box, make sure Design View is selected and the combo box is empty. Then click OK
  2. If the Toolbox is not displaying, on the Form Design toolbar, click the Toolbox button
    On the Toolbox, click Text Box and click anywhere in the Detail section (the wide area under the Detail bar)
  3. To add two new sections, right-click the Detail section and click Form Header/Footer
  4. To save the form, on the Form Design toolbar, click the Save button
  5. Type EmployeesOfficeContact as the name of the form and press Enter
  6. Close the form

 

Introduction to Report Design

 

 

By its structure, a report resembles a piece of paper that you can use to prepare printable information to the user. Like a form, a report is made of a Selector button, two rulers, two scroll bars, and a Detail section. Unlike a form, by default, a report presents a Page Header and a Page Footer sections:

 

Report Design

 

As you can see, a report appears with three default sections. Like a form, you can add another section on top and another at the bottom of the report. To do this, you can right-click the body of the report and click Report Header/Footer. You can also click View -> Report Header/Footer on the main menu. Additionally, unlike a form, you can create as many sections on a report as you see fit. This is referred to as grouping fields.

As mentioned for the form, you can add any control in any section of the report but, unlike a form, it is very important how you use the sections of a report as they have greater influence on the printed product. For this reason, each section can be configured for a specific task. If you are creating a regular report that displays one record per page, you may not need a Report Header and a Report Footer sections. If you are creating a brochure or a document that appears as a catalogue or a book, you may need a Report Header and a Report Footer sections. The sections would appear as follows:

  • The Report Header section is the first page of the report. It can be created and configured like the cover of a magazine or brochure. If you are creating a regular report, you can use the Report Header to display a label that would appear in the beginning of the printed document even if it doesn't appear on its own page. For example, a Report Header section can be used to create a title for the report
  • The Page Header appears on top of each piece of paper printed with the following exception: if the report contains a Report Header section and the Report Header section is configured as a whole page, the Page Header would not appear on the first page printed
  • The Detail section is used to display regular data of the report. It is presented on each page except on the first if the report includes a Report Header and on the last if the report includes a Report Footer sections
  • The Page Footer section is like the section that displays page numbers or footnotes of a book. It appears on each page
  • The Report Footer section is the last page of the document. It is like the back page of a book or a magazine.

 

Practical Learning: Creating Reports Fields

 

 

  1. On the main menu, click Insert -> Report
     

New Report

  1. On the New Report dialog box, make sure Design View is selected and the combo box is empty. Then click OK
  2. To add a control, on the Toolbox, click Text Box and click anywhere in the Detail section
  3. To add two new sections, right-click anywhere in either section of the report and click Report Header/Footer
  4. To save the report, on the Report Design toolbar, click the Save button
  5. Type ListOfAssets as the name of the report and click OK
  6. Close the report

 

MOUS Topics

 

 

S22

Switch between object views

S17

Use the Control Toolbox to add controls

 

Exercises 

 

 

Yugo National Bank

 

 

  • Open the Yugo National Bank database. Start a new form in Design View. From the Toolbox, add two text boxes to the Detail section. Save the form as AccountTypes and close it.

 

 

 

 

 

7.

Data Field Design

 

 

 

Fields Design Techniques

 

 

Introduction

 

 

As a database is expanding, so are its objects. For example, many of the tables created by the Database Wizard lack some fields that otherwise would not suit a particular scenario. As we learned already, you can add new fields to a table. Since such new fields are not added to the corresponding forms or reports, you have to insert these fields in the appropriate objects. Even though the Form Wizard or the Report Wizard can be used to create quick objects, you still have the option of changing or improving their look by moving fields around and changing the sequence of fields’ navigation.

 

The modification and design of a form or a report is done in Design View. A form or report in Design View displays the same window controls we have used when performing data entry. This time, these controls are equipped with handles that allow you to move them anywhere on the object.

To perform your design, a form is equipped with two rulers, one horizontal on the top section of the form, and one vertical on the left section, to help you be more precise with dimensions. To assist with controls design, you can use a toolbox equipped with buttons, text boxes and other items to give a lot of flexibility to your application. You also have the originating table, the field list, on your screen in case you want to add an item that you did not include in the beginning. When you do not need any or both of these two items, you can hide them by clicking their buttons on the toolbar.

 

Form and Report Design Accessories

 

 

During form design, there are accessories you will display and dismiss at will. These are the Field List, the Toolbox, and the Properties window. All of these objects are modeless windows. Therefore, you can display one at a time or all of them at the same time and continue designing your form. The Field List is a small window that displays a list of items that are related to the form you are building. These items are from the data source that could be a table or a query.

 

To display the Field List, on the Form Design toolbar, you can click the Field List button Field List. When the Field List is displaying on your screen, the button appears clicked. To dismiss the Field List, click the same button. You can also close it by clicking its Close button Close. When the list is not displaying, its button looks "normal".

You can also perform these operations of displaying and dismissing the Field List using the menu bar under View. You can resize the list as needed by dragging one of its borders or corners. 

The Field List

 

 

The Toolbox

The Toolbox presents a list of some of the most common window controls, Some of these controls can be associated with fields of your Field List; some others can be configured to relate to another existing control on the form. Yet, another control can behave independently of anything else that is on the form.

To display the Toolbox, on the Form Design toolbar, click the Toolbox button Toolbox. You can also close it using either the same button on the toolbar, or clicking its own Close button Close. You can also use the menu under View.

 

The Properties Window

 

Made of five property pages, this Properties window displays the characteristics associated with the object or the control that is selected on the form. To get the Properties window of the properties associated with a control, right-click that control and click Properties.

To display the Properties window for the form, double-click the button that is at the intersection of both rulers . You can also click the Properties button Propertieson the Form Design toolbar to toggle the Properties windows.

 

Forms, Reports, and Data Existing Fields

 

 

As mentioned already, on forms and reports, you can create fields that do not exist on tables or queries, as we have done so far in this lesson. Alternatively, when in the New Form or the New Report dialog box, you can select the object that holds the list of fields in the combo box.

The New Form allows

If you had started the design of a form or report already, you can display its Properties window and select an object in the Record Source combo box

 

Record Source

 

Practical Learning: Using Existing Fields of a Table or Query

 

 

  1. Open the Rockville Techno1 database
  2. On the Database Window, click the Forms button if necessary and double-click EmployeesOfficeContact
  3. After viewing the form, to switch it to Design View, on the Form View toolbar, click the View button
    If the Field List window is not displaying and if you are using Microsoft Access 2000 and above, on the Form Design toolbox, click the Field List button
  4. On the form, double-click the button at the intersection of both rulers to display the Properties window of the form
  5. In the Properties window, click the Data property page. Click the arrow of the Record Source button and click Employees. Notice that the Field List is now equipped with fields
    (If you are using Microsoft Access 97, now you can display the Field List button)

 

Data Field Design

 

 

 

Fields Design Techniques

 

 

Forms, Reports, and Queries Fields

 

If you want to use just a few fields from a table or an existing query, you can set it as the source of a form or report. Otherwise, you can create a new list of fields that are retrieved from a table or an existing query. To do this, you must build a query.

To build a new query that would serve as the source of a form or report, when in Design View, display the Properties window for the form or report and click the ellipsis button of its Record Source. Then proceed as we learned to add or insert fields for a query. Once you have finished, you can close the query. It would become the source of data for the object.

If the form or report had already been created with fields that do not exist on the list, these fields on the form or report would become “orphans”. For example, suppose you create a form or report based on a Record Source such as Employees:

A form created using an Employees table

Because you can, suppose you don't want to start the design of a new form but instead decide to change the Record Source of the form to something else like Customers:

Consequently, the fields that were created from the Employees set of records but that don't exist on Customers would have lost their "ties". When such a form or report displays, the "orphaned" controls would display #Name? error:

For such controls, you can then either delete them or change their own data source.

 

 

 

Practical Learning: Creating a Query as a Record Source

 

 

  1. Press F11 to display the Database window
    On the Database window, click the Reports button and double-click the ListOfAssets report
  2. To switch it to Design View, on the Print Preview toolbar, click the View button
  3. Click the button at the intersection of both rulers . In the Data tab of the Properties window, click Record Source and click its ellipsis button
  4. On the Show Table dialog box, make sure the Tables tab is selected. Double-click CompanyAssets and click the Close button
  5. On the list of fields, double-click AssetType, Make, Model, and PurchasePrice
     

  1. Close the Query Builder window
  2. When asked whether you want to save the statement, click Yes
  3. While the caret is still in the Record Source field of the Properties window, press Enter
  4. Notice that the Field List got filled with the fields that were selected
  5. Close the Properties window
  6. Close the report. When asked whether you want to save it, click Yes

 

Form and Report Design: Controls Insertion

 

 

When designing a form or a report, one of the most usual actions you will perform consists of inserting items from the Field List to the form or the report. To add a field, you can drag it from the list to the desired section on the form or report. To drag many fields at the same time, first select them.

To select all items at the same time on the Field List, you can:

  • Double-click the title bar of the field list
  • Click the item on one end of the list, press and hold Shift, and click the item on the other end. In fact, you can use this same process to select fields in a range.

To select fields at random, press and hold Ctrl, then click each one of the desired fields. If you had selected an item but want to remove it from the selection. While still holding Ctrl, you can click the undesired item.

After selecting items on the Field List, to add them to a form or report, you can drag one of them and drop it on the form or report.

Insertion

 

 

 

Practical Learning: Inserting Fields

 

 

Author Note

In the following exercises, there is a 100% guaranty that the fields on our form do not display as those on your form. Therefore, the screenshots are provided only as a guide: they are not showing how your form should or must appear. When we would like you to have the same type of design, we will let you know and we will show you. Based on this, follow only the instructions and don't make any other attempt to change the way your form appears. Don't make it look like ours We have a pretty good idea of what your form looks like. And, if it helps, at least for this exercise: Trust Us.

 

  1. The EmployeesOfficeContact form should still be opened in Design View but behind the Database window. To display it, click any of its sections in the background, avoiding any of the system buttons
    If you have any of the form's accessories (Field List, Toolbox, Properties window), close all of them leaving only the form open.
    On the Form Design toolbar, click the Field List button 
  2. On the Field List, click DateHired and hold your mouse down. Then drag it (DateHired) from the Field List and drop it in the top left area of the Detail section:
     
  3. Drag EmployeeNumber from the Field List and drop it somewhere in the middle of the Detail section 
  4. In the Field List, click FirstName. Press and hold Shift, then click LastName, and release Shift. This allows you to select a range of fields
  5. Click and hold the mouse on the selection. Then drag and drop it under the EmployeeNumber field on the form
     
  6. To select fields at random, on the Field List, click HomePhone. Press and hold Ctrl. Then click EmailAddress, and BillingRate. Then release Ctrl
  7. Click and hold the mouse on the selection. Then drag and drop it in the upper right area of the Detail section
     
  8. Close the Field List
  9. To save the form, on the Form Design toolbar, click the Save button

 

Rulers and Dimensions

 

 

Since the rulers are dimensionally configured, there are divisions inside of the rulers to help you be more precise. Between two numbered dimensions, there are 7 marks that create 8 divisions. The mark in the middle, a little taller than the others, represents the middle of two dimensions. In this site, the middle division will be referred to as ½. The first division on the right side of a number represents 1/8 of a dimension, the 2nd represents 2/8 = ¼ of a dimension, the 3rd represents 3/8, and that is why the 4th represents 4/8 = ½. This is how we will refer to these dimensions.

 

7c.

Data Field Design

 

 

 

Form and Report Design

 

 

Controls Selection

 

To manipulate controls on the form, you will regularly need to select them. When one control is selected, you can change only its characteristics. When many controls are selected, you can make a change that would impact all of them. 

To select a control, you can just click it. A control that is selected displays 8 handles around it:

To select more than one control, at random, click one, then press and hold Shift. While holding Shift, click each of the desired controls. After selecting the controls, release Shift. 

To select controls aligned vertically, click inside of the horizontal ruler above the highest positioned control: everything that would be touched by the fake line will be selected. In the same way, you can select controls that are horizontally aligned by clicking inside the vertical ruler. 

To select many controls in the same area on the form, click next to one of them and draw a fake rectangle that covers each of the desired controls. All controls touched by the fake rectangle would be selected when you release the mouse. 

To select all controls on the form, press Ctrl + A. You can also click inside of one of the rulers on one end and drag to the other end.

Practical Learning: Selecting Controls

 

  1. On the form, click the EmployeeNumber text box. Notice that although only the text box was selected, the corresponding label has its upper-left corner selected also
  2. Press Ctrl + A. Notice that all of the controls/items on the form have been selected:
     

  1. To dismiss the selection, click an unoccupied area in one of the sections of the form
  2. Click the EmailAddress text box. Press and hold Shift. Then click the Middle Name label and the EmployeeNumber text box. Release Shift
  3. Notice that these controls have been selected at random
  4. Position the mouse inside of the horizontal ruler on an eye drop above the FirstName text box until the mouse cursor turns into a down pointing arrow:
     

  1. Then click. Notice that all items under the mouse cursor when it was clicked have been selected
  2. Position the mouse inside of the horizontal ruler at 41/2 until the mouse cursor points down Click and hold your mouse at that position
  3. With your mouse still held, drag left until the mouse pointer is at 27/8:
     

  1. Release the mouse. Notice that all controls that were touched by the waving line have been selected
  2. Position the mouse inside of the vertical ruler to the left of either FirstName, MiddleName, or LastName labels until the mouse pointer turns into a right pointing arrow, then click
  3. Notice that everything horizontally positioned on the right side of the mouse pointer has been selected
  4. Position your mouse inside of the vertical ruler at 11/2 until the mouse turns into a right pointing arrow. Click and drag up until the mouse pointer reaches 5/8:
     

  1. Notice that all controls on the right side of the covered area have been selected. Click an empty area on the form to deselect
  2. Click and hold your mouse on an unoccupied area in the lower-right area of the Detail section without touching any control
  3. While holding the mouse, drag up and left as if you were drawing a rectangle. While dragging, make sure your rectangle covers a few but not all controls. Then release the mouse
  4. Notice that the controls that were touched have been selected
  5. Click an unoccupied area on the form to dismiss the selection

 

 

Controls Moving

 

 

Once a control is selected, as your mouse moves over a selected control, its pointer displays a different cursor. Two of these cursors can be used to move a control:

Pointer

Role

Moves the (one) selected control

Moves the control and includes its dependent, if any.
Also moves a group of selected controls

 

 

Practical Learning: Moving Controls

 

 

  1. Click the EmployeeNumber label to select it
  2. Position the mouse on the upper left corner of the selected control until you see a pointing finger:
     

  1. Click and drag left and right to move the label and position it somewhere 
  2. Click the EmployeeNumber text box to select it
  3. Position the mouse on the selected text box until the mouse pointer turns into an open hand:
     

  1. Click and drag right. Notice that the text box and its label have been moved
  2. To see what the form looks like at this time, on the Form Design toolbar, click the View button
  3. To switch the form back to design view, on the Form View toolbar, click the View button
  4. Position the mouse on the left side of the MiddleName text box. Click and drag down and right as if you were drawing a rectangle. When the mouse reaches and touches the LastName text box, release it. Notice that all the text boxes that the rectangle touched have been selected
  5. Position your mouse on one of the selected controls until you see an open hand. Click the drag left until the MiddleName label is at 1 unit right from the vertical ruler. Notice that all text boxes and their labels have moved
  6. Click the First Name label. Press and hold Shift. Then click the following labels: Middle Name, Last Name, Home Phone, and Email Name to select them. Release Shift
  7. Right-click any of the selected label. Position the mouse on Align and click Left
  8. Click an unoccupied area on the form to dismiss the selection

 

 Controls and Sections Sizing

 

 

Resizing an object allows you to change its height or its width. This can be applied to forms, reports, their sections, or the controls they are hosting. To physically change the width of a form or a report, position the mouse on its right border until the cursor turns into a vertical beam with a double-horizontal arrow:

Then click and drag left or right until you are satisfied.

The height of a form or report is controlled by its sections. For this reason, each section controls its own height. The total heights of all sections constitute the height of the form. Based on this, to resize a form, you must actually resize one or some of its sections. To heighten a section on a form or a report, position the mouse on the lower portion of the section. For the headers or the Detail sections, that will be the upper border of the lower bar. For the lowest section, the mouse must be positioned on the lower border. The cursor turns into a narrow horizontal line with a vertical double-arrow:

To change the width of the form or report and the height of the lowest section at the same time, you can position the mouse on the lower-right corner. The cursor would change into a small square with 4 arrows:

You can then click and drag left, right, up, down, or diagonally.

When the mouse moves over a selected control and reaches one of the handles, the mouse pointer displays a double-arrow cursor. The possible mouse pointers are:

Pointer

Role

Shrinks or heightens the control

Resizes the control in North-East <-> South-West direction

Narrows or widens the control

Resizes the control in North-West <-> South-East direction

Although these pointers can be used to resize one control, they can also be applied to a group of controls.

 

Practical Learning: Resizing Controls

 

 

  1. To increase the height of the Form Header section, position the mouse on the upper border of the Detail bar. Click and drag down until the line reaches the third mark inside the vertical ruler:
     

  1. To narrow the form, click and drag the right border of one of the sections to the right until it is at 4 grid units right from the most right control
  2. Click and unoccupied area on the form to dismiss the selection (just in case a control is selected)
    Click the EmployeeNumber text box to select it
  3. Position the mouse on the lower border of the selected control until the cursor turns into a vertical double arrows:
     

  1. Click and drag down by 2 units. Then release the mouse
  2. Click the FirstName text box to select it
  3. Press and hold Shift
  4. While Shift is still down, click the MiddleName text box followed by the LastName text box and release the Shift 
  5. Position the mouse on the middle right handle of one of the selected controls:
     

  1. Then click and drag left by one unit of the horizontal ruler. Notice that all three text boxes have been narrowed
  2. Click the EmailAddress text box. Press and hold Shift. Then click the DateHired text box, and the FirstName text box. Release Shift
  3. On the main menu, click Format -> Size -> To Narrowest. Notice that all of the selected text boxes have been resized to the narrowest of the group, in this case the FirstName text box

 

Controls Deletion

 

 

If you have added a control or it was created by the Form Wizard or the Report Wizard, you can delete it. You can also delete a group of controls in one step.

To remove a control from the form or report, first click it and press Delete. If you click a text box or a control that is accompanied by a label and delete it, its label is deleted also.

To remove a group of controls, select them and press Delete.

 

Practical Learning: Deleting Controls

 

 

  1. On the form, click the EmployeeNumber text box to select it and press Delete. Notice that the text and its accompanying label have been removed
  2. Click the MiddleName label and press Delete. Notice that only the label has been removed, leaving the MiddleName text box

    Here is what we have learned so far:
     

What we have learned in this section about form and report design

 

At this time we have learned how to select:

o                                One control on the form: You click it

o                                Controls on the same area of the form: You draw a fake rectangle that would touch everyone of them

o                                A few controls on the form: You click one, press and hold Shift, then click each of the desired controls

o                                Select all items that are vertically aligned: you click inside of the horizontal line as if you were dropping a ball that would touch all of them

o                                Select all items that are horizontally aligned: you click inside of the vertical line as if you were throwing a ball that would touch all items on the same line

o                                Select everything on the form: Press Ctrl + A

We also learned how to move:

o                                One control: Drag a pointing finger mouse pointer on the control's upper left corner

o                                A text box with its corresponding label: drag an open hand mouse pointer on it

o                                Many controls: Drag an open hand mouse pointer on one of the selected controls

And we learned how to align:

o                                A control relative to another: once both are selected, right-click one of the selected controls, position the mouse on Align, and make your selection

o                                Many controls relative to another or others. Same thing as above

We learned how to resize a control:

o                                after selecting it, position your mouse on one of its borders or corners and drag the double arrow mouse pointer

  1. Based on this, design the form as follows:
     

  1. After designing the form, to preview it, on the Form Design toolbar, click the View button
  2. Press Tab a few times to move the cursor from one text box to another

 

 Tab Ordering

 

 

The controls on a form are aligned in the order you desire for their sequence. Unfortunately, when you add a control on the form that already has other controls, regardless of the section or area you place the new control, it is sequentially positioned at the end of the existing controls. If you don't fix it, the data entry personnel could have a hard time figuring out how the sequence should be followed. When writing Visual Basic code, you will also find out that the sequence of navigation of controls on a form is very important.

The sequence of controls navigation is set using the Tab Order dialog box. The Tab Order dialog box is available when the form is opened in Design View. Once in Design View, either (1) on the menu bar, click View -> Tab Order; or (2) right-click on the form and click Tab Order.

The simplest and quickest way to rearrange the order of items is to click the Auto Order button. Sometimes, you will not like the arrangement made by the Tab Order dialog box. To rearrange items manually, move a row or a group of rows using the same technique we used to move field names on a table's Design View.

 

Practical Learning: Sequentially Order Controls

 

 

  1. To switch the form to Design View, on the Form View toolbar, click the View button
  2. On the main menu, click View -> Tab Order…
  3. Position your mouse on the left of LastName, on the row header until the mouse turns into a right pointing arrow: 
  4. Click to select the row, and release the mouse
  5. Click and hold your mouse on the same row header
  6. Drag down by two rows and notice the horizontal line that guides you
  7. Then release the mouse
  8. Now that you have seen how to reorder the list of controls, arrange it to have the following sequence (this sequence assumes that your form looks like ours in design):
     

  1. Click OK to acknowledge the order
  2. To preview the form, right-click its title bar and click Form View
  3. On the main menu, click Window -> Size To Fit Form
  4. To save the form, press Ctrl + S
  5. To close the form, press Ctrl + F4

 

Opening an "Un-Openable" Form

 

 

Some of the forms created by the Database Wizard were programmed not to be opened from the Database Window, for good reasons. To explain why, here is an example.

Imagine that you create a form to process credit card payments when a customer has chosen to perform such a form of payment. The form used to process this payment should be opened only when the customer has decided to make a payment with a credit card. The user does not need to open such a form from the Database Window. Therefore, you would prevent this form from being accessed in any other way than from the form that is supposed to request its service. In the Rockville Techno database, such forms are the Project (since every project is related to a particular client, the Projects form should be opened from a chosen client), the Payment (unless performing a payment, and we want a particular payment to be related to the appropriate project, the Payment form should not be opened otherwise), and etc forms.

To open such a form, you have two alternatives: from its parent form or in Design View. To open such a form in Form View (or in Datasheet View if that is the way the database developer wanted to display it), open its parent form, and click the appropriate button to open the desired form (all these dependent forms have their button on the parent form). To open the form in Design View, you don't have to have its parent form; you can (1) right-click the desired form in Database Window and click Design View, (2) click the form to select it and click the Design button on the Database Window.

 

Practical Learning: Opening a Form in Design View

 

 

  1. Make sure any form is closed (this is not necessary but desired)
  2. On the Database Window, make sure the Forms button is clicked
  3. From the Database Window, double-click Projects. Notice that a small message form requests an entry from you; otherwise it would not open the form. Click Cancel. 
  4. Right-click Projects and click Design View. Notice that this time, it opens. 
  5. Close the Projects form by clicking its system Close button 
  6. On the Database Window, click Payments to select it
  7. On the toolbar of the Database Window, click Design. That opens the Payments form in Design View
  8. To close it, click its system Close button

 

MOUS Topics

 

 

S22

Switch between object views

 

Exercises 

 

 

Yugo National Bank

 

 

  1. Open the Yugo National Bank database and open the AccountTypes form in Design View. Set its Record Source to AccountTypes and delete the text boxes on the form. Using its Field List, add its fields to the form and design it as follows:
     

2.      Save and close the form

  1. Use AutoForm to generate a form for each of the following tables and save the form with the following name
     

Table Name

Form Name

Customers

Customers

Employees

Employees

TransactionTypes 

TransactionTypes 

4.       

  1. Design the forms as follows and save them:
     

 

 

 

8.

Properties of Database Fields

 

 

 

Overview of Windows Objects

 

 

Introduction

 

 

In everyday life, an object is an entity that displays or provides some characteristics that set it apart. These characteristics are used to describe the object. For example, an object called Car has such characteristics as its make, model, color, year made, price, and mileage, etc. When put together, these aspects can be used to get good knowledge of what the object looks like and perhaps how it functions. The same concept is used in computer programming, in database development, and in Microsoft Access.

Referring to Microsoft Access, an object is a database field or control that “owns” some characteristics that define or control such aspects as its appearance, its behavior and probably its relationship with other objects of either the same parent or the same database. As objects are different one from another, so are their characteristics. Still, the techniques used to access, read, or change the characteristics of a control or field are shared by all of them, as long as they are being operated upon using Microsoft Access development environment..

 

Access to Controls Properties

 

 

In computer programming or database development, a characteristic of an object is also referred to as its property. On this site, both words will be used interchangeably. When designing a form or report, you can display and review the characteristics of an object using its Properties window.

The properties of an object are divided in three main categories:

  • Characteristics that control the object's appearance are listed in the Format property page
  • Characteristics that control internal or external relationships, as far as data is concerned, are listed in the Data property page
  • The Other property page lists characteristics that don't fit in one of the other groups

When dealing with a particular characteristic, you can access it from one of those property pages or you can use the whole list of properties from the All tab

 

 

Practical Learning: Creating a New Form

 

 

  1. Start Microsoft Access and open the Rockville Techno database that you started
  2. To create a new form, in the Database Window, click Forms and double-click Create Form In Design View.
    If you are using Microsoft Access 97, in the Forms property page, click the New button. In the New Form dialog box, click Design View, make sure nothing is selected in the combo box and click OK
  3. To display the Properties window, double-click the button at the intersection of the rulers

8b.

Properties of Database Fields

 

 

 

Properties Categories

 

 

Introduction

 

Properties are set by changing their values and there are various types of properties. A property is made of two parts: its name and its value:

The name of a property displays on the left gray section. Although you can click it to select it, you cannot change it. The property name can be made of one word such as Width. It can also be made of a combination of words, such as Border Style. On this site, a property will be called by what displays on that left gray section. This means that, if a property displays "Height", we will call it "The Height Property". If it displays "Whats This Button", we will call it "The Whats This Button Property".

The second part of a property displays on the right side of the property name. This is called the value of the property. As properties are intended to fulfill different purposes, there are various categories of properties.

String Properties

 

 

When a property value displays a word or a group of words, such a word or group of words on a field is called a string.  Some of those properties 

already display a value while some others are empty. To set or change such a string, if it is already displaying something, it depends on whether you want to replace the property value or edit it.

To replace the value of a string property, you can click the property name. This would highlight the value. You can then type the desired value, which would replace whatever text the property was displaying. If the property value was empty, you can click the property name and type the desired value. If the property already had a value and you want to edit it, you can click in the value field to position the cursor in the string; then you can use your knowledge of text editing (Home, End, Backspace, Space, and arrow keys) to change the text.

To put the string into edit mode, you can also click the property name, which would highlight the value, then press F2 to position the cursor into the field. If you press F2 again, you would highlight the contents of the field. This means that F2 toggles edit and selection modes. To edit a string already contained in the field, you can also double-click it, which would put it into edit mode.

There are various types of string properties on forms, reports, and other controls. Examples include, among others, the control's name or its caption.

Practical Learning: Viewing String Properties

 

  1. To see examples of string properties, in the Properties window, click the Data tab and click Filter. Notice that it is empty and expects a value
  2. Click Order By to see an example of another string property

Boolean-Based Properties

 

 

Some fields behave like a True or False answer to a question. Such fields can display only one of two values. Both values come in a combo box that displays as the property’s value. There are three categories of these fields in combinations 

of Yes/No, True/False, or On/Off. To change the value of the field, you can first click the property name to reveal its combo box. Then click the arrow of the combo box and select the other value. You can also double-click the property name or its value. This would toggle with the opposite value. With experience, you can also type the first letter of the value, such as y or n and Microsoft Access would complete with the corresponding value.

 

 

 

Practical Learning: Viewing Boolean Properties

 

 

  1. To see examples of Boolean properties, in the Properties window, click the Format tab
  2. Click Record Selectors and notice that it displays an arrow in the property value side. Click that arrow and notice that the list is made of Yes and No
  3. In the same way, examine the Navigation Buttons and the Dividing Lines properties

 

Enumerated Properties

 

 

A set is a list of words that composes the possible values of a property. The list, which is static, which means it cannot be changed, comes as a combo box

 

where the user (in this case the user is the database developer) can select one item from. To access the value of such a property, you can click the property name to reveal its combo box. To change the property value, click the arrow of the combo box and select the desired value from the list. You can also double-click either the property name or the property value. This would display the next value in the list. You can keep double-clicking until the desired value comes up. If you know the values in the list (from experience), you can type the first letter of the desired value and Microsoft Access would complete it with the corresponding value. If you try typing a value that is not in the list, you would receive an error.

 

Practical Learning: Viewing Enumerated Properties

 

 

  1. In the Properties window, click the All tab and click Default View
  2. Click its arrow to see its list of values
  3. Scroll down and click Border Style. Then click its arrow to view its list

 

Numeric Properties

 

 

Some properties, like the string fields, expect you to provide a value. In this case the value must be numeric. There are two types of numbers you will be asked to provide, depending on the property.

 

An integer is a natural number that does not take a decimal portion. Such a number can be made of digits only. For such a field, make sure you provide an integer of appropriate range, as you will possibly be directed to do. The other type of number will be decimal. 

A decimal number, also called a floating-point number, can be made of digits or a combination of digits and one period (or the symbol used as the decimal separator in your language; you can find this out in the Regional Settings of the Control Panel) in between. When setting such a value, make sure that either you type only digits, or you type digits and one decimal separator. The decimal separator can be anywhere in the value, Microsoft Access would take care of formatting it if it judges it necessary.

To change the value of a numeric property, you can click the property name to highlight the property value. Then you can type the desired value. You can also edit the value by clicking the value itself, which would put it into edit mode.

Some numeric properties, such as the color properties, allow you to either type a number (provided you know what number you are typing) or to use an intermediary approach (namely a dialog box) to select an appropriate value.

 

Practical Learning: Viewing Numeric Properties

 

 

  1. In the Properties window, click the Format tab
  2. Scroll down to examine the Width and the Grid X properties

 

Expressions Properties

 

 

Some properties display a value that is a more elaborate string. If you know what value the property should display, namely an expression, 

 

you can just type it. Otherwise, Microsoft Access provides intermediary steps that you can follow to create or build the value. We will see examples of those when we study expressions and queries.

 

Practical Learning: Viewing Expression Properties

 

 

  1. In the Properties window, click the All tab. Scroll down and click Picture
  2. In the right section, click the ellipsis button. Notice that a dialog box is called
  3. Click Cancel on the Insert Picture dialog box
  4. Close the form. If you are asked whether you want to save it, click No

8c.

Properties of Database Fields

 

 

 

Common Characteristics of Database Fields

 

 

Name

 

We have seen so far that, in order to use anything in your database, you must first create it, but the process of creating something depends on its type. For example, tables are created in Datasheet View or designed in Design View. Queries are created by adding fields from existing tables or other queries. Forms and reports are created by adding existing fields or adding independent fields to them. Fields are created and added to these objects.

Like every thing else in your computer, every object or field you use in a database must have a name. In fact, when creating an object, the first property that must be set is its name.

When you start a brand new table in Datasheet View, Microsoft Access assigns various names to its fields (or columns). These are Field1, Field2, etc. We saw how to change these fields. If you start a brand new table in Design View, you must specify a Field Name for each column that will be used.

When you create a simple query, as you select fields from a table or query and add them to the new query, they keep their names and, in this case, the names are held in the originating object (the original table or query). You can still create new fields by combining existing fields from the original table or query. When you create such a new field, you must give it a name. To create a new field in a query, you can select an empty column and, in the field box, assign an expression to it. After doing this, the query would provide a suggested name like Expr1. You can then change the name to something else than Expr1.

If you drag an existing field from a Field List to a form or report, the field is added and it keeps it name. You can check this in the Properties window. If you click a control on the Toolbox and click a form or a report, Microsoft Access would assign in a name based on the control. For example, if you add a Text Box control to a form or report, it would named Text0. If you add a second Text Box, it would be named Text2. Whether you drag a field from the Field list or add a control from the Toolbox, after placing it on a form or report, you can change the name it received.

In the Table Datasheet View, we saw that, in order to change the name of a field, you can double-click it; you can also right-click it and click Rename Column. This puts the field in edit mode and selects it. You can then type the new name and press Enter. In the table Design View, to change the name of a field, you can double-click its name, which would put it in edit mode. Then you can either edit the name or change it completely. In a form or report, you can change the name of a field only while in Design View. To do this, you can access the Properties window of the object. Then, edit or change the string of its Name value.

Practical Learning: Naming Objects

 

  1. The Rockville Techno database should still be opened
    On the Database window, click the Reports button
  2. Double-click the ListOfAssets report to open it in Print Preview
  3. After viewing it, to switch it to Design View, on the Print Preview toolbar, click the View button
  4. In the Detail section of the report, you should have a text box and its accompanying label. If you do, click the Unbound text box and press Delete
    On the Toolbox, click the Text Box control and, on the report, click anywhere under Detail bar
  5. Since the text box was accompanied by a label, click its label and press Delete
  6. On the report, click an unoccupied area to make sure nothing is selected.
    On the report, double-click the newly added text box to select it and display its Properties window
  7. In the All tab of the Properties window, click Name, type txtCategory and press Enter
  8. In the same way, add a new Text Box in the Detail section. Delete its label and change its Name to txtManufacturer
  9. Add another Text Box control in the Detail section. Delete its label and change its Name to txtModelName
  10. Add another Text Box control in the Detail section. Delete its label and change its Name to txtDatePurchased
  11. Add another Text Box control in the Detail section. Delete its label and change its Name to txtUnitPrice
  12. Arrange the fields as follows:
     

  1. Save the report

 

 

Record and Control Source

 

 

We had previously mentioned that there are fields created from tables and used on the objects, and that these objects also use fields that either existed already or fields that are independent of any other. When adding or creating a field on a form or report, if data for that field originates from a previously created column on a table, the field is said to be “bound” because its data is bound to an existing field. If a field is either created as an expression that combines other fields or if the field doesn't depend on any existing field, the field is said to be unbound.

During the design of a form or report, if you drag a field from the Field List to the object, the new control is bound to the field from the table or query on the Field List. If you click a control on the Toolbox and click a section on the form or report, you can then decide whether the field is bound or not. If it is, you can access its Control Source in the Properties window and from the combo box, select a field from the list. Even if you had dragged a field from the Field List, you can change the control it its bound to by selecting a different one on the Control Source combo box. In future lessons, we will see how to create expressions that use a combination of existing such as creating a full name from the first and last names.

 

Practical Learning: Setting Control Sources of Objects

 

 

  1. The Rockville Techno database should still be opened
    Click the button at the intersection of both rulers on the report. Then, in the Properties window, click Record Source and click its ellipsis button
  2. From the list of fields, drag DateAcquired and drop it on PurchasePrice in the lower section of the query
  3. Close the query. When asked to save it, click Yes and press Enter
  4. On the report, click the first or left Unbound text box to select it. On the Properties window, click the Control Source field. Then click the arrow of its combo box and select AssetType
     

  1. In the same way, set the Control Source of the second Unbound text box to Make
  2. Set the Control Source of the third Unbound text box to Model
  3. Set the Control Source of the last two Unbound text boxes to DateAcquired and PurchasePrice
  4. Save the report and close it

 

Visibility

 

 

After adding a field to a form or report, it becomes visible and can be used. An object is referred to as visible if it can visually be located on the screen. A user can use an object only if he can see it. Most of the time, you will not be concerned with this aspect. On the other hand, there are situations that will lead you to create a control but hide it from the user. For example, since you cannot declare a (VBA) variable in Microsoft Access, you can instead create a control such as a text box, make it hold a value that you can use in an expression but hide it from the user who would never need to use such an object.

 

Availability

 

 

In order to use a control on a form or a report, the object that is hosting the control must allow it. For example, the user cannot type text or change the value of a combo box if this action was not made possible. This aspect is controlled in two different ways.

If the value of a text box is set by an expression, the user cannot change it. The other technique that controls the availability of an object is from the Enabled property. If you set it to Yes, which is its default value, the user can type a value into it or change it, provided the control’s value does not originate from an expression. If you set its Enabled property to No, the user will not be able to change the value of the control.

 

Practical Learning: Disabling a Field

 

 

  1. The Rockville Techno database should still be opened
    From the Forms section, double-click CompanyAssets
  2. Click the Asset ID text box and type 12. Notice that it does not allow any value from the user. For this reason, we will disable it
  3. To switch the form to Design View, on the Form View toolbar, click the View button
  4. Double-click the AssetID text box to access its Properties window. In the Properties window, click the Data tab and double-click Enabled to set it to Yes
  5. Notice that its aspect and its label have changed
  6. To switch to Form View, on the Design View toolbar, click the View button
  7. Click the Asset ID text box and notice that, this time, it cannot even receive focus
  8. Save and close the form

 

Field Locking

 

 

During data entry, a user usually clicks a field to give it focus and starts typing. As we will learn, some fields get an automatic number set and controlled by Microsoft Access. Some other fields use data created from an expression. These types of fields do not support data entry and their content cannot be changed directly by the user. In some other circumstances, you will create fields but would not like the user to be able to change their value. For this reason, you can lock such a field.

When a field is locked, the user cannot change its content. This characteristic is directly related to data entry and is therefore available on controls positioned on a form only. To lock a control, after selecting it in Design View, access its Locked property in the properties window and set it to Yes. If the control was previous locked, you can unlock it by setting this property to No.

 

Practical Learning: Locking a Field

 

 

  1. The Rockville Techno database should still be opened
    In the Forms section, right-click CompanyAssets and click Design View
  2. Click the AssetID text box. In the Properties window, double-click the Locked field to set it to Yes
  3. Switch the form to Form View. Then save and close the form

 

Tool tip

 

 

A tool tip is a small yellow border-less box that appears when the mouse is positioned on top of a control for a few seconds. It is a fast means of providing help to the user. Because only the form displays controls in a manner suitable for them, a field can display a tool tip only on a form.

To create a tool tip, while in Design View of the form, access the ControlTip Text property of the field and type anything you want in it.

 

Practical Learning: Setting Tool Tips

 

 

  1. The Rockville Techno database should still be opened
    In the forms section of the Database window, double-click the Clients form and, on the Clients form, click the Projects button
  2. After viewing the Project form, switch it to Design View
  3. Click the Client Name text box (the text box on the right side of the Client Name label). In the Properties window, click ControlTip Text
  4. Type Client company of this project and press Enter
  5. In the same way, click the following controls and change their ControlTip Text property as follows (in the following table, the Control column only refers to text box and the combo box on the form; the name in the Control column is the control on the right side of the label indicated):
     

Control

ControlTip Text

Project Name

Identifier set by the person who created the project

Project Manager

Employee in charge of this project

Client PO #

Purchase Order Number

Project Description

Text that describes this project

Est. Total Billings

Project total billing estimate

Project Begin Date

Date this project must start or started

Project End Date

Date this project should end

Total Hours

Number of hours worked on this project so far

Total Expense

Expenses performed on this project so far

Amount Paid

Amount the client has paid so far

Hours Billing

Total amount earned so far

Total Billing

Total amount billed to date

Amount Due

Total amount due to date

  1. Switch the form to Form View and position the mouse for a few sections on Project Manager:
     

  1. Do the same on various controls
    After viewing the tool tips, save and close the form

 

Status Bar Text

 

 

When a field receives focus, you can display a sentence on the status bar to provide some guidance or suggestion to the user. The text that displays on the status bar should be explicit enough but not too long. When creating it, make sure it can fit in the left section of the status bar, which should be long enough to explain anything.

The process of creating a status bar text depends on the control. To create a status bar text for a table, in the Description section for the field, type the string you want. Such a string would appear when the field receives focus in the table or query Datasheet View. If the field participates in an expression for a field of a query, the status bar text would not appear. 

To create a status bar text for a field on a form, while in Design View, access the Status Bar Text property of the control and type the desired string. Only the controls that can receive focus have a Status Bar Text property. For the same reason, because no field can receive focus on a report, this property is not available for fields on a report.

 

Practical Learning: Setting Status Bar Text for Fields

 

 

  1. Open the Bethesda Car Rental1 database you created and click Tables in the Database window
  2. Right-click the Employees table and click Design View
  3. Click EmployeeID and press Tab twice
  4. In the Description field for the EmployeeID field, type
    Automatic number set by the database engine
  5. Press the down arrow key twice. That puts the cursor in the Description field for the DateHired field. Type Date the employee was hired
  6. For the description of the EmployeeNumber, type Number set by Management 
  7. In the Description of the FirstName field, type Employee’s first name 
  8. In the Description of the MI field, type Middle Initial made of one letter
  9. Complete the descriptions of fields
     
  10. Save the table
  11. To switch to Datasheet view, on the Table Design toolbar, click the View button 
  12. Click a cell under the Date Hired column and observe the sentence on the Status bar
  13. Click under EmailAddress and observe the Status bar
  14. Close the Employees table
  15. Open the Rockville Techno database
  16. From the Forms section of the Database window, open the CompanyAssets form and switch it to Design View
  17. On the form, click the Asset Type text box to select it. In the Other tab of the Properties window, click Status Bar Text
  18. Type Category of asset and press Enter
  19. In the same way, on the form, click the following text boxes and change their Status Bar Text value in the Properties window
     

Text Box

Status Bar Text

Make

The company that manufactures this item

Model

The model displayed on the item

Serial Number

The serial number set by the manufacture

Date Acquired

The date this item was purchased

Purchase Price

The price paid for this item, even if it is being financed

Notes

A description or a few comments about the item

  1. Save the form and switch it to Form View
  2. Click different field and observe the message on the status bar
     
  3. Close the form

 

Database Objects Captions

 

 

A caption is text that guides the user to identify a window or another object. As it is the most important property of a label, it may appear as a significant guide to the user. For a table, a query, a form, or a report, the caption is text that displays on the title bar. For a label, the caption is text the user can read on the control. After creating an object such as a table, a query, a form, or a report, Microsoft Access uses its name as its caption.

The captions of tables and queries cannot be changed (easily). Microsoft uses a combination of the name followed by a colon and space, followed by the category of object. For example, if a table is named Addresses, its title bar would display Addresses: Table

The caption of a query depends on the type of query. If you create the types of queries we have used so far, which consisted of selecting fields, these are called Select Queries. The title bar of such a query would use the same technique as the table but the category of object would be Select Query:

If you create a form using the Form Wizard or if you create a report using the Report Wizard, Microsoft Access would use the name you provided as its caption. If you design a brand new form or report by adding fields to it, it would have a caption as Form1 or Report1 followed by the object category as the Form or the Report. To display its caption, Microsoft Access would use the same convention as seen above:

If you create a report or a form using a wizard, after you have saved the object, its name would be used as its caption:

 

 

Controls Captions

 

 

So far, we have used two techniques to create fields on a table: using the Datasheet View or using the Design View. In Datasheet View, the name you give to a column also becomes its caption. This is one of the limitations of the Datasheet View. Most programming or development environments, including Microsoft Access, separate the name of a field from its caption. The name is used by you and the operating system to identify an object. The caption is most used to guide the user. To help with this, the Design View of a table allows you to make a distinction on these two aspects of a field.

In the Design View of a table, to create a caption for a field, after selecting it in the upper section of the table, in the lower section, click the Caption field and type the desired string. The caption and the name have very little in common, as far as programming is concerned. Although you can provide as caption any string of your choice, you should create it to reflect its corresponding field. For example, you can set the caption of a field named EmployeeNumber as Two Letters Followed by Three Digits as follows:

The caption would display as follows:

Although this works, you should set a (short) caption that indicates what the field is used for. For this example, an appropriate caption could be Empl # or Employee # or Empl. Nbr.

When you select a new field for a query, Microsoft Access applies the same caption that was used in the table for that field. If the field did not receive an explicit caption (when it was created in the table), then, like the table, the query would use the name of the field as caption. You can change the caption of a query’s field to display anything other than the name set in the originating table. To do this, in the box that receives the name of the field, type the desired caption, followed by a colon, followed by the name of the field that will be displayed in the column. Here is an example:

When you run the query, it would display the caption you had set:

To set or change the caption of a form, a report, or a label, access its Properties window. Then, click the Caption field and edit or replace it as necessary. If you delete the Caption of a form or a report, Microsoft Access would use the ObjectName: Category formula to create its caption. 

If you add a new label from the Toolbox to a form or report, the caret would be placed in it so you can create its caption. If you click somewhere else without typing, the label would be cancelled. Therefore, the first action to take when creating a label is to give it a caption, which is done by simply typing the desired string. If the label already exists and you want to edit it, first click it to select it. Then click it again. This would put the label into edit mode. You can then use your knowledge of text editing to change its caption. If you completely delete the caption of a label, the label would be completely deleted.

 

Practical Learning: Setting Objects Captions

 

 

  1. Open the Clarksville Ice Cream database you started in Lesson5 and click Tables in the Database window
  2. Double-click the Employees table to open it in Datasheet View. Observe the captions on various columns such as DateHired, EmployeeNumber, EmailAddress, etc
  3. Switch the table to Design View
  4. In the upper section of the table, click EmployeeID
  5. In the lower section of the view, click Caption. Type Empl ID and press Enter
  6. In the same way, set the captions of fields as follows
     

Field Name

Caption

DateHired

Date Hired

EmployeeNumber

Empl #

FirstName

First Name

MiddleInitial

MI

LastName

Last Name

WorkPhone

Work Phone

EmailAddress

Email Address

ZIPCode

ZIP Code

MaritalStatus

Married?

  1. To save the table, press Ctrl + S and switch the table to Datasheet View
     

  1. Notice that the captions on columns are different (make sure you don't type anything in the fields)
  2. Open the Rockville Techno database and, in the Database window, click Tables
  3. Double-click the Employees tables to open it and, after viewing it, switch it to Design View
  4. In the upper section, click EmployeeNumber
  5. In the lower section, click Caption. Type Empl # and press Enter
  6. In the same way, set the Caption of MiddleName to Middle Name
  7. Change the Caption of Extension to Ext
  8. Change the Caption of EmailAddress to Email Address
  9. Change the Caption of StateOrProvince to State
  10. Change the Caption of PostalCode to ZIP Code
  11. Save and close the table
  12. On the Database window, click the Forms button
  13. Open the Employees form in Design View
  14. Click State/Province and click it again to put into edit mode. Double-click Province to select it and press Backspace twice
  15. Click PostalCode to select the label. Double-click Postal, type ZIP and press the space bar
  16. Click the Billing Rate label and, in the Properties window, click the Format tab
  17. Click Caption. Type Salary and press enter
  18. Switch the form to Form View to see the result
     

  1. Save and close the form
  2. Double-click the EmployeesOfficeContact form to open it to Form View
  3. Notice the caption on the title bar and switch it to Design View
  4. Click the button at the intersection of both rulers. In the Properties window, click Caption. Type Rockville Technologies, Inc. – Employees Contact Information and press Enter
  5. Preview the form
     

  1. Save and close the form
  2. In the Formst section of the Database window, right-click the EmployeesOfficeContact form and click Copy
  3. Right-click a white area in the Database window and click Paste
  4. In the Paste As dialog box, type EmployeesContact in the Form Name and press Enter
  5. In the Database window, click the Reports button
  6. Double-click the ListOfAssets report to view it and then switch it to Design View
  7. Click the button at the intersection of both rulers . In the Format tab of the Properties window, click Caption. Type Rockville Technologies – Company Assets Inventory and press Enter
  8. Preview the report and switch it back to Design View
  9. On the Toolbox, click Label and, on the report, click anywhere under the Report Header bar
  10. Type Company Assets and press Enter
  11. Once again, on the Toolbox, click the Label control and, on the report, click under and to the left of the Page Header bar above the AssetType text box
     

  1. Type Category
  2. In the same section and to the right of the previous label, add another label and set its caption to Make
  3. Add another label to the right of the previous label and set its caption to Model
  4. Add another label to the right of the previous label and set its caption to
    Date Acquired
  5. Add another label to the right of the previous label and set its caption to Price
  6. Using the techniques we reviewed for resizing and moving controls, enlarge each label to the same width as its corresponding text box and move it just above its label:
     

  1. Save the report

 

Text Alignment

 

 

Most fields or controls of a database display text. This includes labels, text boxes, and combo boxes, etc. To enhance the appearance of the fields or controls, you can specify the alignment of text of a control. This property has three values: left, center, or right.

By default, the alignment of text-based fields, including any caption on a label, is set to the left (following US English). The alignment of fields that display numbers or dates is set to the right. If you don't like these suggestions or for any other reason, you can change the text alignment of a field or control.

There are various ways you can change text alignment. After selecting it and while in Design View, the Formatting toolbar provides the Align Left , the Center , and the Align Right buttons. You can click one of these to apply the desired alignment. Alternatively, while in Design View (in Microsoft Access 2000 and later versions, you can change text alignment of fields, excluding the label because it cannot receive focus, even if the form displays in Form View, as long as you display its Properties window first) you can access the Properties window for the field or the label. Then click the arrow of its Align Text combo box property and select one of the available values: Left, Center, or Right.

 

Practical Learning: Aligning Fields Text

 

 

  1. The Rockville Techno database should still be opened and displaying the ListOfAssets report
    On the report, click the Date Acquired label to select it.
  2. On the Formatting toolbar, click the Center button Center
  3. To select another control on the report, on Formatting toolbar, click the arrow of the most left combo box and select txtDatePurchased
  4. In the Properties window, click the Format tab and click Text Align
  5. Click the arrow of the Text Align combo box and select Center
  6. On the report, click the Price label and, on the Formatting toolbar, click the Align Right button
  7. Save the report

 

Font

 

 

A font is an art effect made of designed symbols used to represent letters and other characters on a field, a control or a label. A font is designed by an artist but usually follows a specific pattern. For example a font designed to produce symbols readable in the US English language must be designed by a set of predetermined and agreed upon symbols. These symbols are grouped in an entity called the English alphabet. When designing such a font, the symbols created must conform to that language. Because a font is primarily an art, one font can be significantly different from another and a font is not necessarily a series of readable symbols.

Just like everything else in the computer, a font must have a name. A font is also designed to assume different sizes. Before using it on a data field or label, the font must have been installed (in reality, when working in Design View (even in any application like Microsoft Word), you can type the name of a font in the Font combo box; if the font doesn't exist, it will simply not be used but you may not receive an error). Microsoft Windows installs many fonts during setup. 

The font used on the Microsoft Access application to display its menu and the names of objects is controlled by the operating system. That font is called the System Font. Unless you have a good reason, you should not be concerned with it.

The names of fonts installed on your computer can be seen in the Fonts window accessible from Control Panel. Here is an example (from a Windows 98 installation):

 

Fonts of a computer

 

By default, Microsoft Access uses a font called Arial to display columns and fields on tables, queries, and reports. The default font used on forms is called Tahoma. If you want to use a different font to display text on labels and fields of your database, you can changes these defaults.

To set or apply a font on a label or a field, after selecting it in Design View, you can use the Formatting toolbar which is equipped with the Font combo box. You can click its arrow and select a font from the list. Alternatively, to change a font, access the Font Name property of a label or a field in the Properties window, click the arrow of the property’s combo box and select from the list.

When changing the default font, in other words, if you decide to change the default font, you should use only the most popular fonts that are more likely to be found on your user’s computers. To set or apply a font on a group of labels and/or fields, select the group and either use the Formatting toolbar or, from the Properties window, click the Font Name combo box and select from the list.

Besides its name, a font is also known for its size. The size defines how much height and proportional width would be used to represent the characters of the selected font. To change or set the size of the font used to display the characters of a label or a field, after clicking it or selecting the group of controls, on the Formatting toolbar, you can click the arrow of the Font Size combo box and select a size from the list. You can also click the label or field, access its Properties window and select a size from the Font Size combo box. In both cases, if you want a size that is not in the list of the Font Size combo box, you can simply type the desired natural number and press Enter or Tab. As done for the font names, you can also select a group of labels and/or fields and apply the same size to them.

A font is also characterized by its style. The style controls how the font displays, in normal, bold, italicized, underlined, some of these characteristics or all of them. Here are examples of these characteristics:

 

Style

Example

Regular

Regular Text

Bold

This text is bold

Italic

Italicized section

Underline

The words are underlined

To change or set the font style of a label or a field, after selecting it and while in Design View, on the Formatting toolbar, click the Bold , the Italic , the Underline buttons, only one of them, two of them, or all of them. You can also specify the font style using the Properties window. To do this, first select the label and/or fields. When using the Properties window, the bold style is provided in variations (this also is a setting controlled by the operating system) from the Font Weight combo box as Extra Light, Light, Normal, Medium, Semi Bold, Bold, Extra Bold, and Heavy. The italic style is provided from the Font Italic Boolean field. The underline style is specified using the Font Underline Boolean property. As mentioned for the other font characteristics, you can apply one or more styles on a group of labels and/or fields after selecting the group.

 

Practical Learning: Setting Fonts Characteristics

 

 

  1. The Rockville Techno database should still be opened and displaying the ListOfAssets report in Design View
    In the Report Header section, click the Company Assets label to select it
  2. On the Formatting toolbar, click the arrow of the Font combo box and click Garamond
  3. With the label still selected, click the arrow of the Font Size combo box and select 24
  4. Still on the Formatting toolbar, click the Bold button
  5. To enlarge the selected label, double-click one of its 8 handles
  6. Select all labels in the Page Header section
  7. In the Properties window, click the Format tab and click Font Name
  8. Click the arrow of the Font Name combo box and select Times New Roman
  9. Still in the Properties window, click Font Size. From its combo box, select 10
  10. From the Font Weight property, select Bold
  11. In the Detail section, select all text boxes. Using the Properties window, set their Font Name to Times New Roman and the Font Size to 10
  12. Save the report

 

Fore Color

 

 

The color is a non-spatial characteristic applied on a Windows control or a field to define its visual density of darkness or clarity. This density itself is a numeric value created by combining three numbers that each ranges from 0 to 255 included. The first number is also referred to as red. The second is referred to as green. The third is referred to as blue. A combination of red, green, and blue creates a color. Since each number has 256 values, if you multiply them as 256 * 256 * 256, you get 16777216. This means that various combinations of red, green, and blue produce more than 16 million possible colors.

There are two main aspects you will deal with as related to colors on a field or a control. The most usual way of setting a color on a field is on its characters or letters. This is also referred to as the fore color, which is simply the color of its font. There are various ways you can change the font color of a field or control. After selecting it and while in Design View, on the Formatting toolbar, you can click the arrow of the Font/Fore Color button. This would display a table of colors:

After clicking a color, it becomes selected on top of the button. The next time, if you need the same color, you can just click the Font/Fore Color button and the already selected color would be applied. If, during design, you will keep changing colors, you can permanently display the Font/Fore Color as a window on your screen. To do this, click the arrow of the Font/Fore Color button and drag its short title bar:

This would create a window based on it. 

Unlike Microsoft Excel and Microsoft Word, the Font/Fore Color table of Microsoft Access does not display the names of colors. Here are the names of colors we will use on this site as they are laid on the Font/Fore Color table:

 

Black

Brown

Olive Green

Dark Green

Dark Teal

Dark Blue

Indigo

Gray- 80%

Dark Red

Orange

Dark Yellow

Green

Teal

Blue

Blue-Gray

Gray-50%

Red

Light Orange

Lime

Sea Green

Aqua

Light Blue

Violet

Gray-40%

Pink

Gold

Yellow

Bright Green

Turquoise

Sky Blue

Plum

Gray-25%

Rose

Tan

Light Yellow

Light Green

Light Turquoise

Pale Blue

Lavender

White

 

Names of Preset Colors

 

Besides the Font/Fore Color button on the Formatting toolbar, to set the font color of a field or label, while in Design View, you can right-click it, position the mouse on Font/Fore Color and click one of the preset colors. Once again, you can use only one of the existing colors.

The Font/Fore Color table presents a good and extended list of colors but it does not allow you to customize colors through the Windows Color dialog box. The most extensive way to apply a color consists of creating it from your own combination of red, green, and blue. To do this, while in Design View, access the Properties window for the field or the label and click its Fore Color property. Then click the ellipsis button. This would open the Color dialog box from where you can either select one of the preset colors or create your own.

To provide the selection of colors on Microsoft Windows applications, the operating system provides a common dialog box appropriate for such tasks. The Color dialog box is used for various reasons to let you set or change a color of an object. When it displays, by default, the Color dialog box appears as follows:

This displays a constant list of colors. If none of the available colors is appropriate for the task at hand, you can click the Define Custom Colors >> button to expand the dialog box:

The expanded Color dialog box allows you to either select one of the preset colors or to custom create a color by specifying its red, green, and blue values.

You can change the color in four different areas:

  • The top left section displays a list of 48 predefined colors
  • If the desired color is not in that section, you can click and drag the mouse in the multi-colored palette
  • You can also drag the right bar that displays a range based on the color of the palette. You can scroll up and down by dragging the arrow
  • For more precision, you can type the Red, Green and Blue values in the corresponding text boxes. Each uses a integral value that ranges from 0 to 255

After selecting or specifying a color, you can click OK or press Enter.

 

Practical Learning: Setting Text Font on Fields

 

 

  1. The Rockville Techno database should still be opened and displaying the ListOfAssets report in Design View
    In the Report Header section, click the Company Assets label to select it
  2. On the Formatting toolbar, click the arrow of the Font/Fore Color button and select Red
  3. In the Page Header section, select all labels
  4. Right-click any of the selected labels, position the mouse on Font/Fore Color and, in the table of colors, click Indigo (7th column - 1st row)
  5. In the Detail section, select all text boxes
  6. In the Properties window, click the Format tab and click Fore Color. Then click its ellipsis button
  7. In the Color dialog box, click the Blue colors in the 5th column 4th row in the Basic Colors section
     

  1. Click OK
  2. Preview the report and switch it back to Design View
  3. Save the report

 

Background Color

 

 

You can enhance the appearance of an object by change its background color. This aspect can be applied only to the object that is selected. Based on this, you can paint the background of one section of a form or a report without changing the other sections. In the same way, you can paint the bounding rectangle of a field or a label independent of the other fields or labels.

To change the background of an object, first select it. To select a section of a form or a report, you can click the bar above it. After selecting a section, a label or a field, to change its background, on the Formatting toolbar, you can click the arrow of the Fill/Back Color button. You can also right-click the section, the label, the field or a group selected and position the mouse on Fill/Back Color. In both cases, a list of colors similar to that of Font/Fore Color would display. You can then select the desired color from the table. To get a color that is not in the list, access the Back Color property of the section or object and click its ellipsis button. This would display the Color dialog box. You can then use it as we described for the fore color.

If you do not want a label or field to be painted with a particular color, you can make it transparent by setting its Fill/Back Color property to Transparent. Using the Properties window, you can also make a control such as a text box transparent by using the Back Style property. Its default value is Normal. To be able to see through the control, you can set this property to Transparent.

 

Practical Learning: Setting Background Color

 

 

  1. The Rockville Techno database should still be opened and displaying the ListOfAssets report in Design View
    On the report, click the Page Header bar to select its section
  2. On the Formatting toolbar, click the arrow of the Fill/Back Color button and, from the table of colors, click Pale Blue (6th column - 5th row)
  3. Preview the report and switch it back to Design View
  4. While the Page Header section is still selected, in the Format tab of the Properties window, click Back Color and click its ellipsis button
  5. In the Color dialog box, click the Define Custom Colors >> button. Set the colors to Red=185, Green=220, Blue=255 and click OK
  6. Preview the report and save it
  7. Close the report

 

Special Effects

 

 

Microsoft Access provides some special visual effects used to raise or sink, etc a section of a form or report, a label or a field. These effects can be controlled by using the Special Effect button on the Formatting toolbar, by right-clicking a label, a field or a group of labels and/or fields, positioning the mouse on Special Effect, and clicking from the list. You can also access the effects from the Special Effect property of the Properties window. The special effects appear as follows:

 

Special Effects

 

Practical Learning: Using Special Effects

 

 

  1. The Rockville Techno database should still be opened
    In the Database window, click the Forms button and double-click the EmployeesOfficeContact form to open it in Form View
  2. After viewing the form, switch it to Design View
  3. In the Detail section, select all labels (and only the labels)
  4. On the Formatting toolbar, click the arrow of the Special Effect button and click Special Effect: Sunken
     

  1. Preview the form and switch it back to Design View
  2. In the Detail section, select all text boxes
  3. In the Format tab of the Properties window, click Special Effect and click the arrow of its combo box. Select Shadowed
  4. As we learned when studying how to resize controls, position the mouse on one lower-center handle of one of the selected text boxes and drag it down by one unit to resize the text boxes
     

  1. Switch it to Form View and, on the main menu, click Window -> Size To Fit Form
  2. Save and close the form

 

Borders

 

 

A border is a line that defines the limit of an object. You can control how the border of a label or a field is drawn. The borders of a label or field can be drawn with a variant width of a line.

To specify the thickness of line applied on the borders of a label, a field, or a group of objects, click the arrow of the Line/Border Width button on the Formatting toolbar and select the desired width from the list.

While the Line\Border Width button on the Formatting toolbar is convenient, it does not provide as many variances as the Properties window. The Border Style is used to control how the borders of a control would be drawn. The possible values are Transparent, Solid, Dashes, Short Dashes, Dots, Sparse Dots, Dash Dot, and Dash Dot Dot. They may appear as follows:

The Border Style characteristic can be used in combination with the Special Effect property. Some of these effects depend on the Special Effect value and may not appear as expected.

The Border Color property can be used to control the color used to draw the border of a label or a field. It is used as we described for the Fore Color property.

The Border Width property is used as the Line/Border Width button of the Formatting toolbar.

 

Location

 

 

When you add or drag a control to a section of a form or report, it assumes a distance from the left border of the section and from the lower border of the bar of that section. These two dimensions are referred to as its location. The location of an object is determined by its Top and its Left properties:

The location of an object can be set by dragging its top-left handle or its body when the object is selected in Design View, as we learned already. Alternatively, the top and the left values are set as decimal numbers and they follow the measures on the rulers. To change the location of an object, after selecting it in Design View, change the values of either or both its Top and its Left properties.

 

Practical Learning: Setting the Location of Fields

 

 

  1. The Rockville Techno database should still be opened
    In the Database window, click the Reports button and double-click ListOfAssets
  2. After viewing the report, switch it to Design View
  3. In the Report Header section, click the Company Assets label
  4. In the Format tab of the Properties window, click Top and type 0.417
  5. Click Left, type 0.125 and press Enter
  6. In the Page Header section, select all labels
  7. In the Properties window, click Top. Type 0.04 and click an area in the Report Header
  8. Still in the Page Header section, click Category and, in the Properties window, set its Left property to 0.0833
  9. In the Detail section, select all text boxes and, using the Properties window, set their common Top property to 0.0417
  10. Using the Format tab of the Properties window, set the Left property of the objects on the report as follows:
     

Label

Text Box

Left

Make

 

1.125

Model

 

2.1667

Date Acquired

 

3.2451

Price

 

4.375

 

AssetType

0.0833

 

Make

1.125

 

Model

2.1667

 

DateAcquired

3.2083

 

PurchasePrice

4.25

  1. Save the report
  2. Preview the report and return it to Design View

 

Dimensions

 

 

The width of an object is the distance from its left border to its right border. The height of an object is the distance from its top border to its bottom border. The width and the height of an object are referred to as its dimensions. The width of a form or report is the common width of each one of its sections. All sections use the same width. The height of a form or report is the total height of all of its sections. For this reason, the form and the report do not have a height because they let each section control this characteristic.

The dimensions of a control positioned on a section of a form or report can be illustrated as follows:

The dimensions of an object can be set by dragging one of its middle handles , , , or , when the object is selected, as we learned already. Alternatively, they can be controlled by its Width and its Height properties. Therefore, to change the dimensions of an object, after selecting it in Design View, change the values of either or both its Width and its Height properties.

 

Practical Learning: Setting Fields Dimensions

 

 

  1. The Rockville Techno database should still be opened and displaying the ListOfAssets report in Design View
  2. Click the Report Header bar. In the Format tab of the Properties window, click Height
  3. Type 1 and press Enter
  4. In the Report, click the Page Header bar. In the Properties window, click Height, type .28 and press Enter
  5. Click the Detail bar. In the Properties window, click Height, type .25 and press Enter
  6. Click the Price label. In the Properties window, click Width. Type .3646 and press Enter
  7. Click the PurchasePrice text box. In the Properties window, click Width. Type 0.5833 and press Enter
  8. Click the button at the intersection of the rulers of the report . In the Properties window, click Width. Type 5 and press Enter
  9. Save the report and preview it

  1. Close the report
  2. In the Database window, click the Forms button and double-click the Employees OfficeContact then switch it to Design View
  3. Select all text boxes. In the Properties window, click Height. Type 0.2 and press Enter
  4. Preview and save the form
     

  1. Close the form

 

Tab Ordering

 

 

When performing data entry, we saw that the user can press Enter or Tab to navigate from one field to another. Because a label cannot receive focus, it is not affected by this navigation. The controls that participate in this navigation are part of a group. Participation to this group is controlled by the Tab Stop Boolean property. In order for a control to receive focus when the user presses Tab, the control must have its Tab Stop property set to true. When you add a Windows control to a form, it is directly made part of that group because its Tab Stop property is set to Yes. If you want to remove a control from this group, you can set its Tab Stop property to No. Of course, an alternative is to set its Enabled property to No.

Once a control’s Tab Stop property is set to Yes, it must receive a number. Each control that is part of the Tab Stop group must have a unique number. Fortunately, Microsoft Access makes sure that this rule is followed. The number must be a natural number whose minimum must be 0 and whose maximum must be the total number of controls that can receive focus – 1. The number is set using the Tab Index property.

When you add controls to the form, Microsoft Access checks whether the control can receive focus. If the control can, its Tab Stop property is set to Yes and it receives an incremental number as its Tab Index. You are allowed to change this number following the rules stated above. If you change the number to a number that already exists, Microsoft would renumber the sequence to make sure a number is not repeated. The best way to deal with this aspect is through the Tab Order dialog box as we saw but if you know how you want to control this property, you can set it as you wish.

 

AutoFormat

 

 

Microsoft Access Design Templates

 

 

We saw that, when you create a database using the Database Wizard, you have the option of applying one of the designs provided by Microsoft Access and you can apply it to your forms and reports. In the same way, if you create a form using the Form wizard, as we have done in previous lessons, you can select one of the designs and apply it to the form. This concept also applies to reports.

If you create a form or report in Design View, you would have only the Standard design. You can still apply one of the designs supplied by Microsoft Access. To do that, open the form or report in Design View. Then, on the main menu, click Format -> AutoFormat... The AutoFormat would appear and allow you to select any of the available designs. After selecting a design, you can click OK

 

Creating a Form Template

 

 

If you design a good looking form or a report and want to use its design in other databases, you can add it to the list of designs of the AutoFormat dialog box. To do that, open the form or report in Design View, then, on the main menu, click Format -> AutoFormat... On the AutoFormat dialog box, click Customize. The Customize AutoFormat dialog box allows you to modify or delete one of the existing designs, or create a new one. 

 

The AutoFormat Dialog Box

 

Practical Learning: Using AutoFormat

 

 

  1. The Rockville Techno database should still be opened.
    In the Forms section of the Database window, right-click the EmployeesContact form and click Design View
  2. On the main menu, click Format -> AutoFormat...
  3. In the Form AutoFormats list box, click International and click the Options button
     

  1. Click OK

 

MOUS Topics

 

 

S22

Switch between object views

S37

Move and resize a control

S38

Modify Format Properties (font, style, font size, color, caption, etc.)

S39

Use the Control Toolbox to add controls

 

Exercises

 

 

Yugo National Bank

 

 

  1. Open the Yugo National Bank database.
    Open the Customers form in Design View. Change the caption of the form to 
    Yugo National Bank - Account Setup and close it
  2. Open the Customers table in Design View, change the Description property of the following Field Names and their Caption as follows:
     

Field Name

Description

Caption

CustomerID

Incremental number generated automatically

 

DateCreated

Date the account was created

Date Created

AccountNumber

Number created by this bank

 

AccountTypeID

Type of account, as Checking, Saving, etc

 

CustomerName

Name registered on this account. Can be a person or a business

Customer Name

Address

Where the customer wants to receive statements. PO Box allowed

 

ZIPCode

 

ZIP Code

LastUpdate

Specifies the last time any information was changed on this account

Last Update


  1. Save and close the table
  2. Open the Customers form in Design View and change the captions of the labels as follows:
     

Yugo National Bank - Customers Account Setup: This form will be used by the person who creates accounts for customers to enter the necessary information to create a new account.

5.      Change the Status Bar text of the following text boxes:

Name

Status Bar Text

DateCreated

Date the account was created

AccountNumber

Number created by this bank

CustomerName

Name registered on this account. Can be a person or a business

Address

Where the customer wants to receive statements. PO Box allowed

LastUpdate

Specifies the last time any information was changed on this account

6.      Save and close the form

7.      Open the Employees form in Design View. Change the caption of the form to
Yugo National Bank - Employees Records and change the captions of its labels as follows: 

Yugo National Bank - Employees Records


  1. Save and close the form
  2. On the AccountTypes form, since the user cannot change the value of the AccountTypeID text box, lock it, disable it, chisel it, and make it bold
  3. On the Customers form, since the user cannot change the value of the CustomerID text box, lock it, disable it, chisel it, and make it bold
  4. On the Employees form, since the user cannot change the value of the EmployeeID text box, lock it, disable it, chisel it, and make it bold
  5. On the TransactionTypes form, since the user cannot change the value of the TransactionTypeID text box, lock it, disable it, chisel it, and make it bold

 

Tenley Associates

 

 

  1. Open the Tenley Associates database.
  2. Open the Departments form in Design View and, using the AutoFormat dialog box, apply the Stone design with all options. Since the user cannot change the value of the DepartmentID text box, lock and disable it. Change the font color of the text boxes to Dark Blue. Adjust the design of the form as follows:
     

Tenley Associates - Departments


  1. Save and close the form
  2. Redesign the Employees form as follows:
     

5.      Save and close the form

 

Watts A Loan

 

 

  1. Open the Watts A Loan database and open the Customers table in Design View. Change the descriptions and captions of fields as follows:
     

Field Name

Description

Caption

CustomerID

Automatic number generated by the database itself

 

AccountNumber

 

Account #

Address

Where the customer wants statements to be sent

 

ZIPCode

 

ZIP Code

2.      Save and close the table

  1. Use AutoForm to generate a form for the Customers table. Save the form as Customers and design it as follows:
     

Watts A Loan - Customers


  1. Save and close the form
  2. Open the Employees table in Design View. Insert or add the following fields:
     

Field Name

Caption

EmployeeID

No Change

FirstName

No Change

LastName

No Change

Title

No Change

WorkPhone

No Change

Address

 

City

 

State

 

ZIPCode

ZIP Code

Country

 

HomePhone

 

Salary

 

Notes

 

6.     
Save and close the table

  1. Use AutoForm to generate a form for the Employees table. Save the form as Employees and design it as follows:
     

Employees Form


  1. Save and close the form
  2. On the Customers form, since the user cannot change the value of the CustomerID text box, lock it, disable it, chisel it, and make it bold
  3. On the Employees form, since the user cannot change the value of the EmployeeID text box, lock it, disable it, chisel it, and make it bold

 

9.

Database Operators and Operands

 

 

 

Introduction to Operators and Operands

 

 

Author Note

Microsoft Access and Microsoft Visual Basic are not case-sensitive. Therefore, any word we are going to use that involves a field, its name, and new words we will introduce in this section, whether written in uppercase, lowercase or a mix, as long as it is the same word, represents the same thing. Based on this, the words TRUE, True and true, as related to Microsoft Access, represent the same word. In the same way, if the words NULL, Null, and null are used in an expression, they represent the same thing.

 

Introduction to Data Types

 

The fields we have been using allow the user to enter, view, or change data of a database. Because there are so many types of values a user can be asked to deal with, the values in the fields are categorized by types. In the next lesson, we will see how to specify what type of value should or can be entered in a field and what type of value should be prevented. At this time, we will review the categories of data that are considered in a database.

A string is any word or group of words considered as an entity.

A Boolean value is one that can be expressed in only one of two values. For example, either it is 1 or it is 0, either it is true or it is false, either it is yes or it is no.

An integer is a natural number that displays without a decimal place. Examples of integers are 18, 16763, and 1450.

A byte is a small number that ranges from 0 to 255.

A double, also called double precision, value is a number that can display a decimal portion, using the character set as the decimal separator in Control Panel. For US English, that character would be the period. The expression “double-precision” means that this number provides a high level of precision. Valid decimal numbers are 12.55, 3.14159 or 9.80336

A date is a value that counts the number of days that have elapsed from a certain point of reference. How a date displays in a field is based on some conventions set by Microsoft Access, Microsoft Windows, or you. There are also rules you must respect. Examples of dates are 28/06/1998, 10-8-82, January 10, 1865

A time is a value that counts the number of seconds that have elapsed since midnight of a certain day. The time also displays following some conventions set in Control Panel, by Microsoft Access, or the person who created the database. Examples of time values are 10:42 AM and 18:06

A currency is a numeric type used to represent money value in a field.

Overview of Operators and Operands

 

The data fields we have used so far were created in tables and then made available to other objects, queries, forms, and reports, so those objects can implement their own functionality without worrying about displaying empty or insignificant fields. In various scenarios, you will need to display a field that is a combination of other fields. For example, you may need to combine a FirstName to a LastName fields in order to create a FullName field, or, to calculate an employee’s weekly salary, you may need to retrieve the value of a Salary field and multiply it with the value of a total number of hours worked in a week. Most, if not all, of these expressions use what we call operators and operand.

An operation is a technique of using a value or a field, or to combine two or more values or data fields to either modify an existing value or to produce a new value. Based on this, to perform an operation, you need at least one value or field and one symbol. A value or field involved in an operation is called an operand. A symbol involved in an operation is called an operator.

A unary operator is one that uses only one operand. An operator is referred to as binary if it operates on two operands.

The Assignment Operator =

 

In order to provide a value to an existing field, you can use an operator called assignment. Its syntax is:

VariableName = ValueOrVariable

The operand on the left side of the = operator is referred to as the left value or Lvalue. This operand must always be able to be written to. In other words, it cannot be a type of constant we will review next. The operand on the right side of the operator is referred to as the right value or Rvalue. It can be a data field or a constant.

There are two main ways we will use the assignment operator. Imagine you already have a field and you want to display the value of that field in another field. In the Control Source of the new field, you can write an expression that assigns the existing field. Here is an example that assigns the value of an existing FirstName field to a new field using the Control Source property:

In some other cases, the assignment operator will be part of a longer expression. We will see examples we move on.

 

 

The Positive Unary Operator +

 

 

Algebra uses a type of ruler to classify numbers. This fictitious ruler has a middle position of zero. The numbers on the left side of the 0 are considered negative while the numbers on the right side of the 0 constant are considered positive:

 

-∞

 

-6

-5

-4

-3

-2

-1

 

1

2

3

4

5

6

 

+∞

   0

-∞

 

-6

-5

-4

-3

-2

-1

 

1

2

3

4

5

6

 

+∞

 

A value on the right side of 0 is considered positive. To express that a number is positive, you can write a + sign to its left. Examples are +4, +228, +90335. In this case the + symbol is called a unary operator because it acts on only one operand. The positive unary operator, when used, must be positioned to the left side of its operand.

As a mathematical convention, when a value is positive, you do not need to express it with the + operator. Just writing the number without any symbol signifies that the number is positive. Therefore, the numbers +4, +228, and +90335 can be, and are better, expressed as 4, 228, or 90335. Because the value does not display a sign, it is referred as unsigned.

 

The Negative Unary Operator -

 

 

As you can see on the above ruler, in order to express any number on the left side of 0, it must be appended with a sign, namely the - symbol. Examples are -12, -448, -32706. A value accompanied by - is referred to as negative. The - sign must be typed on the left side of the number it is used to negate.

Remember that if a number does not have a sign, it is considered positive. Therefore, whenever a number is negative, it MUST have a - sign. In the same way, if you want to change a value from positive to negative, you can just add a - sign to its left. In the same way, if you want to negate the value of a field and assign it to another field, you can type the – operator on its left when assigning it.

 

Constants

 

 

Introduction

 

 

A constant is a value that does not change. The constants you will be using in your databases have already been created and are built-in Microsoft Access. Normally, Visual Basic for Applications (VBA), the version of Microsoft Visual Basic that ships with Microsoft Access also provides many constants. Just in case you are aware of them, you will not be able to use those constants, as Microsoft Access does not inherently “understand” them. For this reason, we will mention here only the constants you can use when building regular expressions.

The algebraic numbers you have been using all the time are constants because they never change. Examples of constant numbers are 12, 0, 1505, or 88146. Therefore, any number you can think of is a constant. Every letter of the alphabet is a constant and is always the same. Examples of constant letters are d, n, c. Some characters on your keyboard represent symbols that are neither letters nor digits. These are constants too. Examples are &, |, @, or !

 

True or False

 

 

In Boolean algebra, something is considered True when it holds a value. The value is also considered as 1 or Yes. By contrast, if something does not hold a value, it is considered non-existent and not worthy of consideration. Such a thing has a value of False, 0, or No. In reality, everything in your database has a value, as far as the database engine is concerned. To retrieve such a value, you can just find out if the value of a field is existent or not.

The comparison for a True or False value is mostly performed on Boolean fields, such a case is the Single Parent field of the student registration objects (table, form, possibly query, and report) of the ROSH database. If a record has a check mark, the table considers that such a field is True. If the check box is not checked, then it holds a False value.

 

NULL

 

 

While the True and False constants are used to find out whether a check box is marked or not, the database provides another constant used to find out whether a field is empty. This can be done using the Null constant.

When a field holds a value, the value would be considered using the comparison operators we will learn shortly. If a field doesn't hold a value, it is considered NULL. It is very important to understand this: the fact that a field is empty doesn't mean that it is NULL.

 

Microsoft Access Operators

 

 

The Square Brackets Operator: []

 

 

When reviewing name rules for our objects in Microsoft Access, we saw that we should use names that are made of one word (no space). In reality, Microsoft Access, as mentioned already, is particularly flexible with names. It uses a mechanism to delimit a name when such a name is involved in an operation. The operator used to specify the beginning of a name is the left or opening square bracket [. At the end of a name, a right or closing bracket is used. To be safe, whether a name is made of one or more words, Microsoft Access prefers including it in square brackets.

In an operation, also called an expression, instead of using such a name as FirstName, you should use [FirstName]. Of course, if a name is made of more than one word, which is frequent on database objects created using the Database Wizard, you must always include it in square brackets. An example would be [Video Titles Subform]. The field we used earlier to assign a FirstName value to another can be written as follows:

 

 

The Collection Operator: !

 

 

The objects used in Microsoft Access are grouped in categories called collections. For example, the forms belong to a collection of objects called Forms. The reports belong to a collection of objects called Reports. The data fields belong to a collection called Controls. Based on this, all forms of your database project belong to the Forms collection, all of your reports belong to the Reports collection, and all controls you are using belong to the Controls collection.

To call a particular object in an operation, using the exclamation point operator, type the name of the collection followed by the ! operator, followed by the name of the object you need to use. For example, if you have a text box called FirstName and you want to refer to it, you can type Controls!FirstName. Here is the same example as earlier that assigns a FirstName field to a text box using its Control Source property:

The name of the collection is used to perform what is referred to as qualification: the name of the collection “qualifies” the object. In other words, it helps the database engine locate the object by referring to its collection. This is useful in case two objects of different categories are being referred to. Since you cannot have two fields with the same name on the same form or report, it is safe to omit the Controls name of the collection when referring to a field.

Whether you use the Database Wizard or you create your own objects, Microsoft Access allows two objects to have the same name, as long as they do not belong to the same category. For example, you cannot have two forms called Employees in the same database. In the same way, you cannot have two reports named Contracts in the same database. On the other hand, you can have a form named Employees and a report named Employees in the same database. For this reason, when creating expressions, you should (with emphasis) qualify the object you are referring to, using its collection. Therefore, when an object named Employees is referred to in an expression, you should specify its collection, using the ! operator. An example would be Forms!Employees which means the Employees form of the Forms collection. If the name of the form is made of more than one word, or for convenience (strongly suggested), you must use square brackets to delimit the name of the form. Therefore, the form would be access with Forms![Employees].

To refer to a control placed on a form or report, you can add the name of the control at the end of the expression. Because the control belongs to its collection, it can be accessed with the ! operator:

 

 

The Period Operator: .

 

 

In previous lessons, we learned that a property is something that characterizes or describes an object. For example, users mainly use a text box either to read the text it contains, or to change its content, by changing the existing text or by entering new text. Therefore, the text the user types in a text box is a property of the text box. To access the property of an object, type the name of the object, followed by a period, followed by the name of the property you need. The syntax used is:

Object.PropertyName

The property you are trying to use must be a valid property of the object. In Microsoft Access, to use a property of an object, you must know, either based on experience or with certainty, that the property exists. Even so, unfortunately, not all properties are available.

 

Double Quotes ""

 

 

A string is an empty space, a character, or a group of characters that you type or provide to a control and you want this character or this group of characters to be considered "as is". In other words, the expression or the control that receives the string should keep it or them the way you supplied it or them, unless you specify otherwise.

A string can be an empty space or one character, such as $ or w; a group of characters, like home or Manchester United or Verbally speaking, I mean… Ah forget it. Most of the time, you will want the database to keep this character or group of characters exactly the way you or the user supplied them. In order to let the program know that this is a string, you must enclose it in double quotes. From our examples, our strings would be "$", "w", "home", "Manchester United", and "Verbally speaking, I mean… Ah forget it". To assign a string to a field, in the Control Source of the field, you can type the assignment operator followed by the double-quoted string. Here is an example:

 

 

The String Concatenator: &

 

 

The & operator is used to add one string to another. It can also be used to append the contents of two controls, or expressions. This is considered as concatenating them. For example, it could allow you to concatenate a first name and a last name, producing a full name. The general syntax of the concatenation operator is:

Value1 & Value2

To display a concatenated expression in an unbound field, use the assignment operator on the field. Here is an example:

Here is an example of the form in Form View:

Once again, you should include the name of a field in square brackets. To concatenate more than two strings, you can use as many & operators between any two expressions as necessary. After concatenating the strings or values, you can assign the result to another value or expression using the assignment operator. The syntax used is:

=Field1 & Field2 & Field_n

Here are examples

=FirstName & " " & LastName

This would display, for example, Boniface Dunkirk

=[LastName] & ", " & [FirstName]

This would produce, for example, Chang, Helene

=[Address] & " " & [City] & " " & [State] & " " & [ZIPCode] & " " & [Country]

This would display a complete address in a field

 

The Parentheses Operators: ()

 

 

Parentheses are used in two main circumstances: in procedures or in operations. The parentheses in an operation help to create sections in an operation. This regularly occurs when more than one operators are used in an operation. Consider the following operation: 8 + 3 * 5

The result of this operation depends on whether you want to add 8 to 3 then multiply the result by 5 or you want to multiply 3 by 5 and then add the result to 8. Parentheses allow you to specify which operation should be performed first in a multi-operator operation. In our example, if you want to add 8 to 3 first and use the result to multiply it by 5, you would write (8 + 3) * 5. This would produce 55. On the other hand, if you want to multiply 3 by 5 first then add the result to 8, you would write 8 + (3 * 5). This would produce 23.

As you can see, results are different when parentheses are used on an operation that involves various operators. This concept is based on a theory called operator precedence. This theory manages which operation would execute before which one; but parentheses allow you to control the sequence of these operations.

 

Arithmetic Operators

 

 

The Addition: +

 

 

The addition is used to add one value or expression to another. It is performed using the + symbol and its syntax is:

Value1 + Value2

The addition allows you to add two numbers such as 12 + 548 or 5004.25 + 7.63

After performing the addition, you get a result. You can provide such a result to another field of a form or report. This can be done using the assignment operator. The syntax used would be:

= Value1 + Value2

 

The Subtraction: -

 

 

Subtraction is performed by retrieving one value from another value. This is done using the – symbol. The syntax used is:

Value1 - Value2

The value of Value1 is subtracted from the value of Value2. After the operation is performed, a new value results. This result can be used any way you want. For example, you can display it in a control using the assignment operator as follows:

= Value1 - Value2

 

The Multiplication: *

 

 

Multiplication allows adding one value to itself a certain number of times, set by the second value. The multiplication is performed with the * sign which is typed with Shift + 8. Here is an example:

Value1 * Value2

During the operation, Value1 is repeatedly added to itself, Value2 times. The result can be assigned to the Control Source of a field as. The expression would be written as follows:

= Value1 * Value2

 

The Integer Division: \

 

 

Dividing an item means cutting it in pieces or fractions of a set value. For example, when you cut an apple in the middle, you are dividing it in 2 pieces. If you cut each one of the resulting pieces, you will get 4 pieces or fractions. This is considered that you have divided the apple in 4 divisions. Therefore, the division is used to get the fraction of one number in terms of another.

Microsoft Access provides two types of results for the division operation. If you want the result of the operation to be a natural number, called an integer, use the backlash operator "\" as the operator. Here is an example:

Value1 \ Value2

This operation can be performed on two types of valid numbers, with or without decimal parts. After the operation, the result would be a natural number. The result of the operation can be assigned to a field using the assignment operator:

= Value1 \ Value2

 

The Division: /

 

 

The second type of division results in a decimal number. It is performed with the forward slash "/". Its syntax is:

Value1 / Value2

After the operation is performed, the result is a decimal number. The result of the operation can be assigned to a field using the assignment operator:

= Value1 / Value2

 

The Exponentiation: ^

 

 

Exponentiation is the ability to raise a number to the power of another number. This operation is performed using the ^ operator (Shift + 6). It uses the following mathematical formula:

yx

In Microsoft Access, this formula is written as y^x and means the same thing. Either or both y and x can be values or expressions, but they must carry valid values that can be evaluated.

When the operation is performed, the value of y is raised to the power of x. You can display the result of such an operation in a field using the assignment operator as follows:

=y^x

 

The Remainder Operator: Mod

 

 

The division operation gives a result of a number with or without decimal values, which is fine in some circumstances. Sometimes you will want to get the value remaining after a division renders a natural result. The remainder operation is performed with keyword Mod. Its syntax is:

Value1 Mod Value2

The result of the operation can be used as you see fit or you can display it in a control using the assignment operator as follows:

= Value1 Mod Value2

 

 

 

 

9b

 

Database Operators and Operands

 

 

 

 

Logical Operators

 

 

Introduction

 

Databases and other programming environments provide operators you can use to perform data analysis. The operators used are called logical operators because they are used to perform comparisons that produce a result of true or false (there is no middle result: something is not half true or half false or "Don't Know"; either it is true or it is false).

The Equality =

 

The equality operator is used to compare two values for similarity. The syntax of this operation is:

Value1 = Value2

If Value1 and Value2 hold the same value, then the comparison produces a True result. If they hold different values, the comparison renders a False value

Inequality <>

 

To find out if two fields hold different values, you can use the inequality operator which is represented by <>. Its syntax is:

Value1 <> Value2

This comparison is performed between Value1 and Value2. If they hold different values, then the comparison produces a True value (make sure you understand this property of Boolean algebra). If they hold the same value, the comparison produces False:

This shows you that the equality (=) and the inequality (<>) operators are opposite each other.

 

 

Less Than <

 

 

The "Less Than" operator uses the following syntax:

Value1 < Value2

If Value1 holds a value that is lower than that of Value2, the comparison produces True. If Value1 holds a value that is greater or similar to that of Value2, the comparison renders false:

 

 

Less Than Or Equal <=

 

 

When comparing two values, you may want to know whether two fields hold the same value or if one is lower than the other. This comparison can be performed with the "Less Than Or Equal To" operator. It is represented by <=. Its syntax is:

Value1 <= Value2

If both operands (Value1 and Value2) hold the same value, then the comparison produces a True result. If Value1 holds a value that is lower than that of Value2, the comparison still produces a True result. By contrast, if the value of Value1 is higher than that of Value2, the comparison renders a False result:

Note that the > and the <= operators are opposite each other.

 

Logical Operators: Greater Than >

 

 

The > operator is used to find out whether one value is "Greater Than" another. Its syntax is:

Value1 > Value2

The operation is performed on the values of Value1 and Value2. If Value1 holds a value greater than that of Value2, then the comparison produces True. Otherwise, the comparison produces False. That is, if the value of Value2 is greater than or equal to that of Value1, then the comparison produces False:

 

 

Greater Then Or Equal >=

 

 

If you have two values and want to find out whether they hold similar values or the first is greater than the second, you can use the >= operator whose syntax is:

Value1 >= Value2

If both Value1 and Value2 hold the same value, then the comparison renders a True result. Similarly, if the left operand, Value1, holds a value greater than that of the right operand, Value2, the comparison still produces True. If the value of Value1 is less than the value of Value2, the comparison produces a False result:

Therefore, < and >= are opposite.

 

The NOT Operator

 

 

To deny the presence, the availability, or the existence of a value, you can use the Not operator. This operator is primarily used to reverse a Boolean value. For example, we have learned that False is the opposite of True. In the same way, True is the opposite of False. If you want to compare a value as not being True, the Not True expression would produce the same result as the False value. For the same reason, the expression Not False is the same as True.

 

The IS Operator

 

 

To validate something as being possible, you can use the IS operator. For example, to acknowledge that something is NULL, you can use the IS NULL expression. In the same way, to validate that something is not null, you can use the expression Is Not NULL.

 

The IN Operator

 

 

The IN operator is used to check whether a record or a group of records is found in a group.

 

10.

Introduction to Data Types

 

 

 

Overview of Data Types

 

 

Introduction 

 

 

A data type represents the kind of information that a particular field should or must hold. Every field in your database objects (tables, forms, and reports) should have the right type and it is your role to select the most appropriate of them. This helps both you and the user who performs data entry. Furthermore, a good design will cause you less headache when

 

creating calculated expressions. Imagine trying to multiply a FirstName by a DateHired. As much as you can, you should make sure that the right kind of data is typed in the right field.

Microsoft Access helps you allow or exclude categories of data in database fields. Using this, you can make sure that the user would not type a contract's date in a project's contact name. To manage different forms of information you enter in a database, Microsoft Access helps you organize data by categories.

 

Techniques of Controlling Data Entry Properties

 

 

To make your database efficient, in some circumstances, or depending on the project (or customer), you should exercise as much control as possible on data entry. Without considering that data entry people are not intelligent enough, it is your job to help or guide them by allowing the right type of information in a field. This control is mostly exercised at two levels: tables and forms.

To control data entry at the table level, a database environment like Microsoft Access provides data types. To specify a data type for a field on a table, you must open the table in Design View and select a data type under the Data Type column for the corresponding column. Because the list of data types may appear short to you, each data type provides some options that allow you to configure how data in that column either would be selectively entered or would display. To do this, after selecting a data type in the Data Type combo box, in the lower section of the table, you can format or further configure the column.

After a field has been configured on a table, when that field is used in a form, it would respect the formatting that was done on the table. Even if you create an unbound field on a form, you can still control how it accepts or rejects data. Therefore, data entry can also be configured at the form level. To provide this functionality, a form provides the same properties as the lower portion of the table.

To further control how data is entered and/or how it is displayed in a field, both the table in Design View and the Properties window in Form Design provide special characteristics.

The lower part of the table Design View is made of two sections: the property pages on the lower left and the properties help section on the lower right:

The kind of Data Type you set for a column in the upper section controls what displays in the lower section of the view. The General property page controls regular features common to the selected data type:

Field Size: The Field Size property is available for a data type and since data types are specified only on a table, it is available only on a table. The Field Size depends on the type of data selected but it is available only for text and numbers.

Format: The Format property is used to specify how the value(s) for a column should display

The Lookup tab allows you to specify a feature that is particular with a specific data type of the upper section of the field.

Once you have selected a data type for a certain field in the upper section of the view, that data type will provide its own sub-categories. To display the sub-categories of a data type, select that data type in the upper section of the view.

 

 

Strings and Data Types

 

 

Introduction

 

 

We have defined a string as an empty text, a letter, a word or a group of words considered “as is”. This type of data is created on a table by selecting the Text data type. A Text data type allows the user to type any kind of characters or group of characters. This field can hold up to 255 characters.

 

Practical Learning: Setting Appropriate Data Types

 

 

  1. From the resources that accompany this book, copy the Rockville Techno1 database to your Exercises folder and then open the Rockville Techno1 database
  2. In the Database window, click the Tables button if necessary
    From the Tables section, open the Employees table and switch it to Design View
  3. Notice that the default Data Type of most fields is Text

 

Field Size

 

 

The size of a string is usually considered as the number of characters it contains or may hold. When creating a field that would hold text, the default size provided is 50 characters, as the number 50 is set in the Field Size property. You can therefore decrease or increase this size for any number between 1 and 255. The default value, 50, is enough in most cases, such as providing a (short) description for a product.

When setting the Field Size property by itself, the database would make sure that the user can only type so many characters. For example, it is very unlikely to have a first name of a person that is 50 characters. In this case, you can safely reduce the number of characters to 20 or 30. On the other hand, if you are creating a column whose length is hard to predict, you can set the length to a reasonable value. There are other ways you can decrease the number of characters that are allowed in a field. Over all, you should be able to predict the types of values that would be entered in the fields of a column.

 

Practical Learning: Setting Field Sizes

 

 

  1. In the upper section of the view, click FirstName
  2. In the lower section of the view, click Field Size and type 20
    This will allow the user to type only 20 characters
  3. In the upper section of the view, click MI and press F6 to move the caret to the lower section of the view
  4. As the caret is on the Field Size field, type 1 
  5. Set the Field Size of LastName to 20 
  6. Set the Field Size of Address to 100
  7. Save the table

 

Text Input Masks

 

 

Because users can be tempted or distracted to enter just anything in a Text field, Microsoft Access provides techniques to control what goes in a field and what must be prevented. This is the role of a mask. A mask is a technique of creating sections, also called placeholders, in a field. A section can be configured to accept only a letter, only a digit, a character or a digit, any symbol, nothing, or to display a particular symbol that the user cannot change. When creating the mask, you will use some predefined characters and create a combination of your choice.

Before creating a mask for a field, Microsoft Access comes with various masks you can apply to a field to control user's input such as dates, times, US Social Security Number, Currency values, etc. To apply one of these masks, you can use the Input Mask Wizard. To do this, first set the Data Type of the desired field to Text. Then, in the lower section of the table, click the Input Mask property and click its ellipsis button . This would start the wizard.

In the first page of the Input Mask Wizard, you can choose one of the popular provided formulas including US and Canada telephone number, Social Security Number, ZIP Code, etc:

If none of the masks suits your need, you can create a new one and add it to the list. To do this, click the Edit List button. This would bring the Customize Input Mask Wizard dialog box:

After creating a new mask, click Close. Once you have located the desired mask, you can click it and click Next to continue. The second page of the wizard allows you to accept or customize the mask you had selected. Once you are ready, you can click Next. The third page presents an option that allows you to specify how the value in the field will be stored in the database. It presents two radio buttons and you can either accept the suggestion or select the other and click Next. The fourth page of the wizard does not do much. It simply lets you know that the wizard is ready to create the mask. Therefore, you can click Finish.

If none of the masks provided by the wizard suits you, you can create your own. To do that, click the Input Mask property for the desired field and use the following characters to create the mask:

 

Character

Used to enter or accept

0

A single digit

9

A single digit or space

#

A digit, space, + or –

L

An alphabetical character

?

A letter

A

A letter or a digit

a

A letter, a digit, or nothing

&

A character or space

C

A character, space, or nothing

.

A decimal place holder; for US English, this would be the period

,

Thousand separator; for US English, this would be a comma

:;-/

Date and time separator, as specified in the Regional Settings of Control Panel

<

A letter; the letter will be converted to lowercase

>

A letter; the letter will be converted to uppercase

!

Anything; the mask is filled from right to left for this position

|

Anything; the character that follows this one will be displayed itself. For example, if you type |L, the letter L would be displayed instead of being used a mask

 

You can use any of these symbols to create a mask. If you want to include a word or sentence as part of the mask, type it in any section as desired. Here are examples of Custom Masks:

 

Mask

Example 1

Example 2

Example 3

LL

dh

fT

Gm

>LL\-00

WE-47

 

 

#0L

8f

16a

04t

>LL\-000

WE-883

 

 

000\-000\-0000

265-387-6498

 

 

##\-##

02-37

-9-5+

-6-35

&#\-L0\-##

5-u5-00

 

 

\(000") "000\-0000

(301) 294-6464

 

 

!\(999") "000\-0000""

( ) 392-3873

 

 

00\-00\-00\-00

28-73-68-46

 

 

>00\-LLLL\-0

78-DRUG-9

 

 

>L<LLL

Jean

 

 

>L<?????????????

Helene

Antananarivo

 

 

Practical Learning: Using Input Masks

 

 

  1. The Clarksville Ice Cream database should still be opened and displaying the Employees table in Design View
    In the upper section of the table, click EmployeeNumber
  2. In the lower section, click Input Mask, type >LL-000 and press Enter
  3. In the upper section, click ZIPCode and press F6. In the lower section, change the Input Mask to 00000
  4. Open the Clarksville Ice Cream database that you started in Chapter 4 and open its Employees table in Design View
  5. In the upper section of the table, click WorkPhone and, in the lower section, click Input Mask
  6. On the right side of the Input Mask field, click the ellipsis button
     

  1. In the first page of the of the Input Mask Wizard, click Phone Number (in Microsoft Access 2000, it should be selected by default) and click Next
  2. In the second page, press Tab twice to position the caret in the Try It edit box. Type 0000000000 to test it
     

  1. Click Next
  2. In the third page, click the With The Symbols In The Mask radio button
     

  1. Click Next and click Finish. Notice the new mask in the field
  2. Save the table

 

Strings Formats

 

 

After a user has entered data in a field, without or without the influence of a mask, you can specify how the value of the field should be displayed. This is controlled by the Format property. To assist you with this configuration, the Format property depends on the type of data set for the field.

After creating a mask, if you want to prevent duplicate data, remember to specify this in the Indexed property.

 

Practical Learning: Setting Fields Format 

 

 

  1. From the resources that accompany our lessons, copy the Bethesda Car Rental1 database and paste it into your Exercises folder. Then open the Bethesda Car Rental1 database
  2. Open the Employees table in Design View
  3. In the upper section of the view, click EmailAddress
  4. In the lower section of the view, click Format. Type < to make sure the content of the Email Address field will be converted to lowercase
  5. In the upper section, click MI
  6. In the lower section, click Format, type >
  7. Click Input Mask, type L and press Enter
  8. Open the Rockville Techno1 database and, from the Tables section, open the Employees table in Design View
  9. In the upper section of the table, click State
  10. In the lower section, click Input Mask, and type >LL and press Enter
  11. In the upper section of the table, click EmployeeNumber
  12. In the lower section, click Input Mask. Type >LL\-000;0;_ and press Enter

 

The Memo Data Type

 

 

The Memo data type functions like the Text except that it can hold a longer text up to 64000 characters. The text is mostly provided as ASCII. This means that there is no formatting.

 

Practical Learning: Setting Memo Types

 

 

  1. Open the Rockville Techno database and, from the Tables section of the Database window, open the Employees table in Design View
  2. Under the Field Name column, click Observations. Press Tab, type m and press Enter. Notice that the data type has been set to Memo
  3. Save the table

 

MOUS Topics

 

 

S1

Determine appropriate data inputs/outputs for your database

S12

Use multiple data types

S15

Use the Input Mask Wizard

 

Exercises 

 

 

Yugo National Bank

 

 

  1. Open the Yugo National Bank database. Open the AccountTypes table in Design View and change the Data Type of the Description field to Memo. Save and close the table
  2. Open the AccountTypes form in Design View. Delete the Description text box (and its accompanying label). Using the Field List, add the Description field to the form where the other Description text box was
     

     
    Save and close the form
  3. In the Customers table, reduce the possible length of characters of the Address field to 50 characters then save and close the table
  4. Reduce the possible number of characters of the Address column of the Employees table to 50 characters then save and close the table

 

Tenley Associates

 

 

  1. Open the Tenley Associates database. Configure the EmployeeNumber field of the Employees table so that examples of possible numbers would be 648-DL-TG or 762-7D-GG or 376-88-BP. That is, an employee number is made of three sections separated by a dash symbol. The first section is made of 3 digits and only digits. The first character of the second section can be a letter or a digit. The second character of the section section can and must only be a letter. The third section must be made of 3 letters
  2. Change the ZIPCode of the Employees table to allow only 5 letters

 

 

 

Watts A Loan

 

 

  1. Open the Watts A Loan database. In the Customers table, reduce the Address field to allow only 50 characters then save and close the table
  2. Open the Employees form and create a few employees records
  3. Open the Customers form and create a few accounts

 

11.

Using Data Types

 

 

 

Numbers

 

 

Introduction

 

 

A number is a digit (0, 1, 2, 3, 4, 5, 6, 7, 8, or 9), a combination of digits, or a combination of one or more digits, a separator, and one or more digits. Microsoft Access provides three techniques or categories of numbers. These should be applied appropriately to make your database as effective as possible. To specify that a column will contain only numeric values, after displaying the table in Design View and selecting the column under Field Name, set its Data Type to Number, Currency, or AutoNumber.

When reviewing strings, we saw that the Field Size property of a Text data type was used to specify the number of characters of the string. Numeric data types also use the Field Size property but it is used to control the type or range of numeric values that would be accepted or excluded from the field. While the Data Type column allows you to select the category of number, the Field Size property actually specifies the (Microsoft Visual Basic) data type that will (programmatically) be applied to the field.

 

Natural Numbers

 

 

A natural number is one that contains one digit or a combination of digits. Examples of natural numbers are 122, 8, and 2864347. When a natural number is too long, such 3253754343, to make it easier to read, the thousands are separated by a special character. This character depends on the language or group of languages and it is called the thousands separator. For US English, this character is the comma. The thousands separator symbol is mainly used only to make the number easier to read.

To support different scenarios, Microsoft Access provides different types of natural numbers:

Byte: A byte is a small natural number that is between 0(included) and 255(included). This type of number can be applied to such items as persons’ ages, number of students in an elementary classroom, number of rooms in a regular house, number of pages of a magazine or newspaper, etc. If you are creating a column that will need this range of values, after setting its Data Type to Number set its Field Size to Byte.

Integer: An integer is a natural number larger than the Byte. It can hold a value between 
-32,768 and 32,767. Examples of such ranges are the number of pages of a book. For a column that would hold this range of values, set its Field Size to Integer.

Long Integer: A long integer is a natural number whose value is between 
–2,147,483,648 and 2,147,483,642. Examples are the population of a city, the distance between places of different countries, the number of words of a book. For such a field, set its Data Type to Number and its Field Size to Long Integer.

In our examples, we were giving types of columns for each kind. It is important to note that, since a long integer can hold larger numbers than the integer, anything applied as an integer can also be used as a long integer. For example, you can use a long integer to represent the number of pages of a book, even if the books in a collection are not expected to hold more than 1500 pages. In the same way, since an integer is larger than a byte, anything that fits in a byte can also be used as an integer. Based on this, an integer can be used to represent the categories items in a collection, even if the items are not expected to be higher than 200. For example, you can use an integer to count the number of keys on a computer keyboard, knowing that this number is expected to stay below 148.

 

 

Practical Learning: Using Natural Numbers

 

 

  1. Open the Clarksville Ice Cream database and, from the Tables section, click the New button
  2. In the New Table dialog box, click Design View and click OK
  3. Set the first Field Name to ScoopsID and make it a press the down arrow key
  4. Set the second Field Name to Scoops and press Tab
  5. Set its Data Type to Number and press F6
  6. In the Field Size combo box, select Byte

 

Automatic Numbers

 

 

If you create a column that will be used to keep an index of records as they are entered and/or deleted, you can set its Data Type to AutoNumber. This would ask Microsoft Access to complete that field with automatically generated numbers for a column whose numbers you don't need to control. This technique is highly used for the first field of a table.

 

Practical Learning: Using an Automatic Number

 

 

  1. The Clarksville Ice Cream database should still be opened with the Table1 in Design View
    In the upper section of the table, click ScoopsID and press Tab
  2. Change the ScoopsID Data Type to AutoNumber
  3. Close the table to save it. Give it the name Scoops and press Enter
  4. When asked whether you want to create a Primary Key, click No
  5. Open the Employees table in Design View
  6. In the upper section of the table, click EmployeeID and press Tab
  7. Click the arrow under the Data Type and click AutoNumber
  8. Save the table

Real Numbers

 

 

A real number is a number that displays a decimal part. This means that the number can be made of two sections separated by a symbol that is referred to as the Decimal Separator or Decimal Symbol. This symbol is different by language, country, group of languages, or group of countries. In US English, this symbol is the period as can be verified from the Regional (and Language) Settings of the Control Panel:

On both sides of the Decimal Symbol, digits are used to specify the value of the number. The number of digits on the right side of the symbol determines how much precision the number offers.

Microsoft Access provides two types of decimal numbers:

Single: A single is a decimal number whose value can range from –3.402823e38 and –1.401298e-45 if the number is negative, or from 1.401298e-45 and 3.402823e38 if the number is positive. To use this type of numbers on a field, set its Field Size to Single.

Double: While the Single data type can allow large numbers, it offers less precision. For an even larger number, Microsoft Access provides the Double data type. This is used for numbers that range from 1.79769313486231e308 to –4.94065645841247e–324 if the number is negative or from 1.79769313486231E308 to 4.94065645841247E–324 if the number is positive.

Similar to the relationships among natural numbers, a Single can fit a Double. In fact, you may see that, with experience and if you check the databases (and VBA code) of most programmers, they use the Double most of the time. Although the Double type uses more memory (Is computer memory still expensive? I guess not.), it offers higher precision than the Single, which sets its preference.

 

Currency Numbers

 

 

The Currency data type is used for a column made for monetary values. For such a column, set its Data Type to Currency. During data entry, the user can type a decimal number and press Enter, Tab or click somewhere else. The number would then be converted to represent a monetary value. The number would also display the currency symbol on its left. Like the Decimal Symbol, the character used for currency depends on the country or a group of countries. It can also be verified in the Regional (and Language) Settings of Control Panel in the Currency section.

The Currency data type does not have a Field Size property on database objects. Instead, it uses the Format property to specify how the number would be displayed:

 

 

Practical Learning: Using the Currency Data Type

 

 

  1. Open the Clarksville Ice Cream database and open the Employees table is Design View
  2. In the upper section of the table, click Salary and press Tab. Click the arrow of the combo box and select Currency
  3. Save the table

 

Boolean Data Types

 

 

Introduction

 

 

A datum is referred to as Boolean when it can assume only one of two values. It can be either Yes or No, True or False, On or Off, non-zero or 0. Such a field is appropriate when you want the user to indicate the state of a value.

To specify that a field is Boolean, set its Data Type to Yes/No.

 

Boolean-Based Options

 

 

To support different ways of expressing a Boolean field, Microsoft Access provides various options. After setting the Data Type of a field to Yes/No, you can control how the field would be presented to the user.

The most classic way of representing a Boolean value consists of displaying a check box:

With this layout, the user can either click the check box or give it focus and press the space bar. Alternatively, if you prefer, you can let the user type a value. In this case, after setting the field’s data type to Boolean, in the lower section of the table in Design View, click the Lookup property page and, on the Display Control combo box, select one of the available items:

The default option is Check Box. If you select Text Box, then the user will be able to type True, False, Yes, No, On, Off, 0, or any number. Once the user types one of these values and presses Enter, Tab, or clicks somewhere else, you can control how the field would display the value. To do this, in the lower section of the table in Design View, click the General property page and, in the Format property, select one of the available options:

If you set the Format property to Yes/No and if the user types 0, the field would display No; if the user types any other number, the field would display Yes.

If you set this property to True/False and if the user types 0, the field would display False; if the user types any other number, positive or negative (but it must be a number) the field would display True:

 

 

Practical Learning: Using Boolean Field

 

 

  1. The Clarksville Ice Cream database should still be opened with the Employees table in Design View
    In the upper section of the table, click MaritalStatus and press Tab
  2. Set its Data Type to Yes/No
  3. In the lower section of the table, click the Lookup property page. From the Display Control combo box, select Text Box
  4. Click the General tab and, in the Format property, make sure that Yes/No is selected
  5. Save the table

 

Document and Object Linking

 

 

Introduction

 

 

Object Linking and Embedding (OLE) is a technique that consists of adding in your database (not just database, but our discussion will stop to Microsoft Access databases as if OLE had to do only with Microsoft Access) an object that was created using another application. The technique used to include such an object is particularly easy. Its configuration or involvement can be the subject of speculation. Over all, Microsoft Access does not care much what type of object you want to add to, or include in, your database. It is left to you to decide why you want to include the object and what type of object this would be. Some objects (can tremendously) increase the size of your database.

To use an OLE object in a field, create the data field in the Design View of a table and set its Data Type to OLE Object.

 

Objects and Data Fields

 

 

After setting the Data Type of a field as OLE Object, since the object is external, there are not too many options or properties provided by the table. The application in which you created or will create the object should control it. To actually include an external object into the field, whether using the table Datasheet View or the form in Form View, the user can right-click the field and click Insert Object. This would open the Insert Object dialog box that presents two options to create or select the object:
 

  • If you want to use an application installed in your application to create the document, you can click the Create New radio button. Then, in the Object Type list, click the application and click OK
  • If the object has been created and resides on a portable media (floppy disk, CD, DVD, etc), on your hard drive or on the network your computer is connected to, you can click the Create From File radio button and click Browse. This would bring the Browse dialog box that allows you to locate and select the document

 

Practical Learning: Using OLE Objects

 

 

  1. Open the Bethesda Car Rental1 database and open the Cars table in Design View
  2. Notice that the Picture field has its Data Type set to OLE Object. Switch the table to Datasheet View
  3. Click any cell under the Model column and, on the main menu, click Format -> Freeze Columns
  4. Scroll to the right to make sure you can see both the Model and the Picture columns
  5. Right-click the first empty cell under Picture and click Insert Object…
  6. On the Insert Object dialog box, click the Create From File radio button and click the Browse button
  7. In the Browse dialog box, using the tree list under the Directories label, locate the folder that contains the resources of our lessons and select it
  8. In the File Name list box, click accent.bmp
     

  1. In the Browse dialog box, click Open and, in the Insert Object dialog box, click OK
  2. Click the second cell under Picture, the one that is empty. Notice a rectangle box drawn in the cell
  3. On the main menu, click Insert -> Object… Click the Create From File radio button and click the Browse button. Notice that the Browse dialog box remembers the last folder used.
  4. In the File Name list box, click cherokee.bmp and click Open. Then click OK
  5. On the main menu, click Format -> Unfreeze All Columns
  6. Close the table. When asked whether you want to save it (the question is stated because the structure of the table was modified when we froze the columns, not because we added the pictures), click No
  7. On Database window, click the Forms button and double-click the Cars form to open it
  8. Click the Next Record button twice to get to the third car
  9. Right-click the white empty area on the top-right section and click Insert Object
     
    Insert Object
  10. On the Insert Object dialog box, click the Create From File radio button and click Browse
  11. Navigate to your Exercises folder. From the list of File Names, click escape and click Open
  12. On the Insert Object dialog box, click OK
     
  13. In the same way, add a picture for each car included in the database. If the picture of a car does not appear in the list, skip it. This simply means that there is no picture
  14. After using the form, close it

 

Hyperlinks

 

 

As mentioned already, an object created with an external application can be added to a database and the object would be included “as is”. When this is done, Microsoft uses an encryption technique to make the object become part of the database so you do not have to remember to include the object when distributing the database. Because of this, objects such as pictures can highly increase the size of a database. This can be convenient at times. Fortunately, the alternative to this scenario is to provide only a link to the document or file from the database to the external document.

The Hyperlink data type allows you to create a field that, when clicked, would open another document on the same computer, on another connected computer, or on the Internet.

 

Date and Time

 

 

Introduction

 

 

Dates and times in Microsoft Access are grouped in a category referred to as Date/Time. Over all, dates and times are considered differently but, to specify that a field would use date, time, or both, set its Data Type to Date/Time. Because there are different ways to display date and time values, the Format property is used to specify how this value should appear. The Input Mask is used to assist the user with data entry.

After specifying that a field will be set for dates or times, you can use the Input Mask property to create mask sections that can assist the user with entering valid dates or times as valid as possible. To support this, you can type a mask in the Input Mask or you can use the Input Mask Wizard, using the characters we reviewed for strings.

 

Practical Learning: Setting Date/Time Formats

 

 

  1. Open the Clarksville Ice Cream database and open the Employees table in Design View
  2. In the upper section of the table, click DateHired
  3. In the lower section of the table, click Input Mask and click its ellipsis button
  4. On the first page of the Input Mask Wizard, click Short Date and click Next
  5. In the second page, accept the suggestion in the Input Mask edit box. Click Next and click Finish
  6. Save the table and close it
  7. To create a new table, on the Database toolbar, click the arrow of the New Object button and click Table
     

  1. In the New Table dialog box, double-click Design View and add the following fields to the table
     

Field Name

Data Type

Description

OrderID

AutoNumber

Automatic number

OrderDate

Text

Date the order was placed

DayOfWeek

Text

Same as Order Date but displays the name of the day of the week

  1. Save the table as CustomersOrders and decline to create a Primary Key

 

Dates Formats

 

 

After a valid date value has been entered in a field, you can specify how the date would display, not necessary how the date was entered. The Format combo box provides already created formats you can use. Those are the most popular formats use for dates. If none of those satisfies you, you can use the following characters or symbols to create a desired format:

 

Format

Used For

Used to Display

d

Days

The day as a number from 1 to 31

dd

Days

The day as a number with a leading 0 if the number is less than 10

ddd

Weekdays

The name of a weekday with 3 letters as Mon, Tue, etc

dddd

Weekdays

The complete name of a week day as Monday, Tuesday, etc

w

Week

The numeric day of the week

ww

Week

The numeric week of the year, ranging from 1 to 53

m

Months

The numeric month from 1 to 12

mm

Months

The numeric month with a leading 0 if the number is less than 10

mmm

Months

The short name of the month as Jan, Feb, Mar, etc

mmmm

Months

The complete name of the month as January, etc

q

Quarters

The numeric quarter of the year

yy

Years

Two digits for the year as 00 for 2000 or 03 for 2003

yyyy

Years

The numeric year with 4 digits

 

To use these letters, simply type the desired combination in the Format field. Here is an example:

This is configured to display a single digit for a day of the month if the day is less than 10, followed by the complete name of the month, followed by the year in 4 digits. During data entry, the clerk can enter a valid date. Once the field looses focus, it displays the date based on the format. Here is an example:

Based on this, you can use any combination of the formats but you should use a combination most regularly used in your language so the users would not be confused.

Besides the indicated characters, you may want to use some other characters to separate them. An example would be January 5, 2004 which uses a comma in the display. To create such sections, include the characters in double-quotes. What you would be doing is to ask Microsoft Access to display such characters “as is” while considering the non-quotes characters as part of the format. Here is an example:

 

 

Practical Learning: Setting Date/Time Formats

 

 

  1. In the upper section of the table, click OrderDate and press Tab
  2. Set its Data Type to Date/Time and press F6
  3. In the lower section of the table, in the Format field, type d mmm yyyy and press Enter. This means that we want the date to display starting with the day of the month, followed by the 3-letter name of the month, followed by the year in 4 digits
  4. In the upper section of the table, set the Data Type of the DayOfWeek field to Date/Time and press F6
  5. Set the Format to dddd and press Enter
  6. Save the table and switch it to Datasheet View
  7. Click the empty field under OrderDate. Type 04/12/1998 and press Enter
  8. Under DayOfWeek, type 4/12/98 and press Enter
  9. Notice that, although both fields received the same date entry, they display it differently
     

  1. Switch the table to Design View

 

Times Formats

 

 

Like dates, time values follow the Regional (and Language) Settings of Control Panel when they display. To make this display friendlier, Microsoft Windows provides some characters you can use to format a time:

To control how time values should display in a field, after setting its Data Type to Date/Time, use the Format property. The characters used to create a format are:

Format

Used For

Used to Display

:

Separator

The character separator for time values
This character is set in the Regional (and Language) Settings of Control Panel 

h or H

Hours

An hour number from 0 to 23
If the hour is less than 10, it would display without the leading 0

hh or HH

Hours

An hour number from 0 to 23
If the hour is less than 10, it would display with the leading 0 such as 08

n or N

Minutes

A minute number from 0 to 59
If the number is less than 10, it would display without the leading 0

nn or NN

Minutes

A minute number from 0 to 59
If the number is less than 10, it would display with the leading 0 such as 06

s or S

Seconds

A second value from 0 to 59
If the number is less than 10, it would display without the leading 0

ss or SS

Seconds

A second value from 0 to 59
If the number is less than 10, it would display with the leading 0 such as 04

ttttt

 

Time Time using the formula of the Long Time of the Regional Settings of Control Panel

am/pm

AM and PM

am (in lowercase) if the time is configured to display in the standard (non military time) and if the time occurs in the morning, or pm (in lowercase) if the time is configured to display in the standard (non military time) and if the time occurs in the afternoon

AM/PM

AM and PM

AM (in uppercase) if the time is configured to display in the standard (non military time) and if the time occurs in the morning, or PM (in uppercase) if the time is configured to display in the standard (non military time) and if the time occurs in the afternoon

a/p

AM and PM

a (in lowercase) if the time is configured to display in the standard (non military time) and if the time occurs in the morning, or p (in lowercase) if the time is configured to display in the standard (non military time) and if the time occurs in the afternoon

A/P

AM and PM

A (in uppercase) if the time is configured to display in the standard (non military time) and if the time occurs in the morning, or P (in uppercase) if the time is configured to display in the standard (non military time) and if the time occurs in the afternoon

AMPM

AM and PM

The AM-PM character. Microsoft Access would refer to the format set in the Regional (and Language) Settings of Control Panel

When combining these characters to create a format, you should abide by the rules of your language. You should refer to the formula set in the Time property page of the Regional (and Language) Settings of Control Panel. Microsoft Access also refers to it for the character separator. If you want to include any other character, type it in double-quotes.

 

Practical Learning: Using the Time Data Type

 

 

  1. Click the first empty field under DayOfWeek. Type OrderTime and press the down arrow key
  2. Type MorningAfternoon and press Tab
  3. Type d and press the up arrow key
  4. Type d and press F6
  5. Click the arrow of the Format combo box and select Short Time
  6. Set the Format of the MorningAfternoon field to AM/PM
  7. Save the table and switch it to Datasheet View
  8. Under OrderTime, type 11:05 and press Tab
  9. Under MorningAfternoon, type 11:05 and press Enter. Notice that the display changes to AM
  10. Switch the table to Design View

 

Date and Time Masks

 

 

As done with Text based fields, you can use the Input Mask property to assist the user with data entry on date and time-based fields. The idea is to create sections and include character separators in the field to help the user know where a number, a month, a year, an hour, a minute, a second, or the AM/PM can be entered. Once again, you have two main alternatives: using a wizard or creating your own mask.

The easiest way of creating a mask for a date or time-based field is to use the Input Mask Wizard dialog box and follow the steps while selecting the options. You can also use the characters specified earlier to create a custom mask.

 

Practical Learning: Creating Date and Time Masks

 

 

  1. In the upper section of the table, click OrderDate, press F6 and press the down arrow key
  2. Click the ellipsis button of the Input Mask field
  3. In the first page of the Input Mask Wizard, click Short Date and press Enter
  4. In the second page, accept the default and press Enter twice
  5. Click Input Mask to select its value and press Ctrl + C
  6. In the upper section, click DayOfWeek and click Input Mask. Press Ctrl + V and save the table
  7. In the upper section of the table, click OrderTime and, in the lower section, click Input Mask then click its ellipsis button
  8. In the first page of the wizard, click Short Time and press Enter three times
  9. Select the Input Mask value and copy it. Then click MorningAfternoon and click Input Mask. Paste the
  10. Save the table and switch it to Datasheet View
  11. Click the empty field under OrderDate. Type 04/12/1998 and press Enter. Under DayOfWeek, type 4/12/98 and press Enter
    12. Notice that, although both fields received the same date entry, they display it differently
     

  1. Switch the table to Design View

 

MOUS Topics

 

 

S1

Determine appropriate data inputs/outputs for your database

S12

Use multiple data types

S44

Add Hyperlinks

 

Exercises 

 

 

Yugo National Bank

 

 

  1. Open the Yugo National Bank database. Open the Employees table in Design View. Just under Title, add a new Yes/No column named CanCreateNewAccount. Set its Display Control to Text Box. Save and close the table.
  2. Open the Employees form in Design View and add the new CanCreateNewAccount field as follows:
     

3.      Save the form and set this field as follows for the following employees:

Last Name

Can Create New Account?

Yuen

1

Marconi

-8

Young

208

Holland

6

Kast

2500

Lourde

-34

Kirkland

-1

4.      Close the form

  1. Open the Customers table in Design View. Change the Data Type of the DateCreated field to Date/Time. Change its Format to Short Date. Use the Input Mask Wizard to set its Input Mask to Short Date. Save and close the table.
  2. Open the Customers form in Design View. Delete the DateCreated text and its accompanying label. Using the Field List, add the DateCreated field to where the other was. Save and close the form.
  3. Open the Customers form and enter the following values in the Date Created text box
     

Account Number

Date Created

 

Account Number

Date Created

28-3782-8

02/04/2002

92-3782-4

02/04/2002

38-4227-5

02/04/2002

68-6434-5

02/04/2002

83-4654-7

02/04/2002

47-4783-2

02/05/2002

82-3763-2

02/05/2002

72-3474-2

02/05/2002

34-5458-4

02/05/2002

29-4586-4

02/05/2002

68-3465-8

02/05/2002

40-4658-6

02/05/2002

56-8468-5

02/05/2002

94-7785-3

02/08/2002

37-5764-8

02/08/2002

34-9754-7

02/08/2002

72-9375-4

02/08/2002

37-5490-6

02/08/2002

20-3454-9

02/08/2002

76-5475-4

02/08/2002

27-3457-4

02/08/2002

 

 

8.      Close the form

 

12.

Introduction to Relationships

 

 

 

Overview of Relationships

 

 

Introduction

 

 

Data entry as we have performed it so far consisted of typing the necessary value in each field. Because a regular database is made of various tables, these objects work as an ensemble to create a product as complete and efficient as possible. As there can be so many objects, one of the rules a database developer should follow is to avoid duplicate entry of data: the same piece of information should not be entered in two different objects. For example, when a person is opening a bank account at a bank, a clerk enters the customer’s information in an object such as a form or a table:

Customer Table Illustration

Introduction to Relationships

 

When the same customer comes back for a transaction such as to deposit money, her information should not be entered again but that information should be selected from the form used to perform transactions:

Field Relationship Illustration

This is the basis of relational database. Relational database is based on the idea that objects of a database are connected or related so they can exchange information. This exchange of information is made possible by creating relationships among objects of a database.

 

The Primary Key

 

 

The Primary Key

If you were asked to create a bank database for the above illustration, the form used when a customer wants to make a deposit probably would need to contain such information as the customer’s name, her bank account, the date of the transaction, and the amount of the deposit. Per haps you would structure the form as follows:

Customer Money Deposit

Customer Name

Bank Account

Transaction Date

Amount of Deposit

 

Based on this, the clerk can simply type the name of the customer and perform the transaction. When the same customer comes back for another type of transaction such as money withdrawal or transfer, the clerk would use another form and enter the customer’s name. The likelihood of typing the name of the customer differently on various forms is really high. For example, when performing a deposit, the clerk may enter the name of the customer as Josiane Tobolowski. On a form used to withdraw money, the clerk may enter the customer’s name as Jozian Toblowsky. Obviously, these are two completely different names. To avoid this type of mistake, the solution is to create an object (table) that would hold the customer’s name and make that name available to (all) other objects involved in transactions. The table that holds the customer’s information may have the following fields:

Customer Information

Full Name

Account Number

Address

Phone Number

Email Address

When a customer needs a bank transaction, the clerk can simply select the customer’s name on a form and continue the transaction. To make this possible, there must be a relationship between the table that holds the customer’s information and the table on which the transaction is performed:

 

Customer Information

 

Customer Money Deposit

 

Full Name

Account Number

Address

Phone Number

Email Address

Double Fleche

Customer Name

Bank Account

Transaction Date

Amount of Deposit

When creating this type of relationship, you would be thinking that, although the customer’s information is needed by various objects of the database, different objects may need different types of information. For example, when performing money deposit, the clerk would need the customer’s account number and her name. If the customer signed to receive newsletters from the bank, when another clerk is preparing these newsletters to customers, he would need the customer’s name and email address but not her account number. For this reason, relational database provides you with the ability to create a special field in the table that holds the customer’s information. This field would be used to communicate with other objects of the database and provide them with the information they need about the customer. The name of this field usually ends with Number, Nbr, or No. Because this field is referred to as an identifier, it sometimes ends with ID. The table that holds a customer’s information may become:

Customer Information

Full Name

Account Number

Address

Phone Number

Email Address

Customer ID

On the objects that need information stored in the customer’s information table, you must create a field that would hold the relationship. For example, you can create such a field on the table used for money deposit. This field does not directly belong to the money deposit table: it acts as an “ambassador”. For this reason, it is called a foreign key. Because such a field belongs to the originating table, it should have the same name as the identifier of the original table. On the other hand, the field identifier will be used to manage the relationship between its table and those tables that need information stored in its table. It is called the primary key. After creating these two fields, they are used to “link” both tables:

 

Customer Information

 

Customer Money Deposit

 

Full Name

Account Number

Address

Phone Number

Email Address

Customer ID

Fleche

Customer Name

Bank Account

Transaction Date

Amount of Deposit

Customer ID

Although in this example of the customer’s information table we illustrated only one field as the primary key, you can use more than one field as the primary key.

In this scenario, what you need the primary key field to do is to keep track of the exchange of information between its table and the tables related to it. In most circumstances, you will not need to enter information in the primary key field. For this reason, you can ask Microsoft Access to provide an automatic number to the field. Based on this, you can set this field’s Data Type to AutoNumber. Of course, you can let the user type the value of the primary key. For example, most companies make sure that two employees don't use the same employee number. In other words, such a number must be unique for each employee. In the same way, in the US, every person must have a unique Social Security Number. Therefore, in some cases, you can let the data entry person provide the value of the primary key. In practicality, you must strongly refrain from letting the user tamper with the primary key. The role of the primary key is to have a unique number that identifies a record in a table. This means that two records should never have the same value of the primary key. For this reason, you should also set it as AutoNumber and let Microsoft Access deal with it.

There are three main ways you get a primary key on a table:

  • If you create a table using the wizard, you will be asked whether you want Microsoft Access to assign a primary key for you
  • If you are creating a table in Design View, you can click the Primary Key button Primary Keyon the toolbar while the designated field is selected, you can also click Edit -> Primary Key from the main menu
  • If you try to save a table created in Datasheet View, since you will not have set a primary key, you will be prompted accordingly. 

 

Practical Learning: Introducing Relationships 

 

 

  1. Start Microsoft Access and create a Blank Database
    If you had already started Microsoft Access, press Ctrl + N. From the New dialog box, click the General property page and click the Database or the Blank Database icon
     

2.      Then click OK

  1. Set the name of the database as Video Collection and click Create
  2. To create your new table, from the Tables section, click the New button
  3. From the New Table dialog box, click Design View, and click OK
  4. Set the name of the first field to ActorID and set its Data Type to AutoNumber
  5. While the field is still selection, on the Table Design toolbar, click the Primary Key button Primary Key
  6. Set its Caption to Actor ID 
  7. In the upper section of the table, under ActorID, set the name of the second field to Actor with the Data Type as Text
  8. Set the Caption of the Actor field to Actor/Actress 
  9. Set the last field as Notes with a Memo as Data Type
     

  1. To switch the table to the other view, on the Table Design toolbar, click the View button.
  2. When you are asked whether you want to save the table, click Yes. 
  3. Type Actors and press Enter. 
  4. Press Enter and enter the following names of actors:
     

ActorID

Actor

 

Eddie Murphy

 

Michael Douglas

 

Glenn Close

 

Bruce Willis

 

Isaac de Bankole

 

Jack Nicholson

 

Laura Linney

 

Demi Moore

 

Tom Cruise

 

Djimon Hounsou

 

Anne Archer

 

Bonnie Bedelia

 

Tom Selleck

 

Paulina Porizkova

 

Lane Smith

  1. Close the table
  2. Create a new table in Design View with the following fields:
     

Field Name

Data Type

Description

DirectorID
(Primary Key)

AutoNumber

Automatic number

Director

Text

Name of a director such as “Mark Lynn” or directors as a group of such as “The Hughes Brothers”

Notes

Memo

Observations about the director or group of directors

  1. Save the table as Directors and switch to Datasheet View
  2. Enter some directors as follows:
     

DirectorID

Director

 

Renny Harlin

 

Tony Scott

 

Tim Burton

 

Eddie Murphy

 

Rob Reiner

 

Jonathan Lynn

 

Spike Lee

 

Steven Spielberg

  1. Create a new table in Design View with the following fields:
     

Field Name

Data Type

Caption

VideoCategoryID
(Primary Key)

AutoNumber

Video Category ID

VideoCategory 

Text

Video Category

Notes

Memo

 

  1. Save the table as VideoCategories and switch it to Datasheet View
  2. Enter a few categories on the table:
     

Video Category ID

Video Category

 

Biography

 

Documentary

 

Fitness – Aerobic

 

Comedy – General

 

Comedy – Police

 

Comedy – Politic

 

Comedy – War

 

Drama – General

 

Drama – Police

 

Drama – Politic

 

Drama – War

 

Sci-Fi – General

 

Sci-Fi – Comedy

 

Sci-Fi – Police

 

Sci-Fi – Politic

 

Sci-Fi – War

 

Cartoon

  1. Close the table
  2. Create a new table in Design View with the following fields:
     

Field Name

Data Type

Caption

Field Size

VideoID
(Primary Key)

AutoNumber

Video ID

 

Title

Text

 

120

CopyrightYear

Number

© Year

Integer

Length

Text

 

20

Notes

Memo

 

 

25.  (To get the © character, you can open Microsoft Word, type (c) then select and copy it. Then paste it in the Caption property of the table field)

  1. Save the table as Videos and switch it to Datasheet View 
  2. Enter a few videos:
     

Title

© Year

Length

A Few Good Men

1993

138 Mins

The Last Boy Scout

1991

105 Mins

The Distinguished Gentleman

 

112 Mins

Batman

1989

126 Mins

Die Hard 2 – Die Harder

1990

124 Mins

Beverly Hills Cop II

1987

103 Mins

Her Alibi

1998

94 Mins

  1. Save the table

 

12b.

Introduction to Relationships

 

 

 

Lookup Fields

 

 

Unbound Lookup Fields

 

 

The fields we have been creating so far were classic text box fields that allow the user to simply type to create a value. Instead of letting the user type the values of a field, if you want, you can establish a list of values that are valid for a certain field. This would allow the user to simply select from that list. Such a field is called lookup field.

The simplest type of lookup field consists of creating a list whose items you know at the time you are creating the database. For example, if a clerk must specify the gender of persons whose records she is creating, since there are only two genders, you can create a list that

 

contains only male and female items. Since there would not be suspicion of a new value, you can safely create such a list. The lookup list is provided through a combo box. To set or change a value in the field, the user can expand the combo box and select an item. The item selected in stored in the field and is stored as a string (as text)

There are three main ways you can create a simple lookup field:

  • In Datasheet View, create or select a field whose value should be selected from a list. Then, on the main menu, click Insert -> Lookup Column…
  • In Datasheet View, create or select a field whose value should be selected from a list. Then right-click the column header and click Lookup Column
  • In Design View, locate the field whose values should be selected from the list and set its Data Type to Lookup Wizard

Any of these actions would launch the Lookup Wizard. Since in this case you would be creating a known list, you should select the second radio button and proceed.

 

Practical Learning: Setting Preset List Of Items

 

 

  1. The Videos table of the Video Collection database should still be opened
    Right-click the Length column header and click Lookup Column...
  2. On the First Page of the Lookup Wizard, click the second radio button
     

  1. Click Next
  2. Click the first empty field under Col1 and type G 
  3. Press the down-arrow key and type PG 
  4. Press the down-arrow key and type PG-13 
  5. Type the other ratings you are aware of, if any:
     

  1. Click Next
  2. For the Column Label, type Rating and press Enter 
  3. Set the ratings of the movies by selecting from the Rating combo box:
     

  1. Close the Videos table
  2. Open the Music Category1 database
  3. Open the Artists table in Design View
  4. Click the Structure field
  5. For its Data Type, choose Lookup Wizard...
  6. When the first page of the Lookup Wizard comes up, choose the second radio button telling the wizard that you will type values for the field, then click Next
  7. Click the empty field under Col1 and type Solo
  8. Press Tab and type Duo
  9. Press Tab and type Band
  10. Press the down arrow key and type Soundtrack
  11. Press Tab and type Orchestra
  12. Press the down arrow key and type Compilation
  13. Press the down arrow key and type Other
     

  1. Click Next. Accept the column label as Structure and click Finish
  2. Click the Lookup tab in the lower part of the Design View
    To make sure that the user can only choose a preset value in the list, set the Limit To List field to Yes
    On the other hand, if you wanted to allow the user to type new entries, you would set the Limit To List field to No (keep in mind that even if you restrict the user to choose only from the list, you can eventually modify that list)
  3. Save, and then close the table

 

Bound Lookup Fields

 

 

As done with the simple lookup, you can create a field whose data would be selected from a list. As opposed to an unbound lookup fields whose values you can predict at the time you are creating a database, a bound lookup field is one whose values are not known in advance. The values for such a field become available as the database is growing.

We mentioned earlier that tables could be linked to exchange information. Based on our illustration, a foreign key field from a table can be used to provide information to its table by

 

retrieving it from the originating table. When creating such a relationship, you should know what table would be providing such information and how the relationship would be managed.

To create a bound lookup field, you select a field and proceed as we saw for an unbound lookup field to open the Lookup Wizard. This time, you would select the first radio button and click Next. This would give you the opportunity to select the table that will supply the necessary information. In this case also, you can specify more than one column to be presented in the list.

 

Practical Learning: Getting Fields Data From External Source

 

 

  1. Open the Video Collection database and open the Videos table in Datasheet View
  2. Click any field under the Notes column.
  3. On the main menu, click Insert -> Lookup Column...
  4. In the first page of the Lookup Wizard dialog, make sure the first radio button is selected and click Next
  5. On the second page, click VideoCategories:
     

  1. Click Next
  2. From the Available Fields list box, double-click VideoCategory
  3. Click Next and Next
  4. For the label, type Category and click Finish
  5. Set the appropriate category for each movie
     

  1. Close the table

 

MOUS Topics

 

 

S3

Establish table relationships

S10

Set primary keys

S13

Modify tables using Design View

S14

Use the Lookup Wizard

S33

Establish relationships

 

Exercises 

 

 

Watts A Loan

 

 

  1. Open the Watts A Loan database. Create a new table in Design View with the following fields:
     

Field Name

Data Type

Additional Information

TypeOfLoanID

AutoNumber

Primary Key
Caption: Type of Loan ID

TypeOfLoan

 

Caption: Type of Loan

Description

Memo

 

2.      Save it as TypesOfLoan and close it

  1. Using AutoForm, generate a form based on the TypesOfLoan table. Save it as TypesOfLoan and design it as follows before saving and closing it
     

  1. Open the TypesOfLoan form and create the following types of loan:
     

Type of Loan ID

Type of Loan

Description

1

Personal

This is loan given as a cashier check to a customer who wants a cash loan

2

Car

This loan will be processed by our partners as car dealers

3

Boat

 

4

Furniture

 

5

Musical Instrument

We have some partnerships in musical instruments stores. This is the type of loan we will make available to the customers they find for us

  1. Open the Transactions table. In the Datasheet View, create a new column using the Lookup (Column) Wizard. Include the AccountNumber and the LastName fields of the Customers table. Set its label to Account # then save and close the table
  2. Open the Transactions table in Design View. Insert a new field just under TransactionID. Name it Processed By and start the Lookup Wizard. Include the LastName, the FirstName, and the Title fields from the Employees table. Save and close the table
  3. Using AutoForm, generate a form based on the Transactions table. Save it as Transactions and design it as follows:
     


  1. Close the form

 

Tenley Associates

 

 

  1. Open the Tenley Associates database and open the Employees table in Design View. Using the Lookup Wizard, configure the DepartmentName field so its value would origin from the DepartmentName Column of the Departments table. Set its label to Department. Save and close the table
  2. Open the Employees form in Design View and delete the DeparmentName text box. Using the Field List, add the DepartmentID field to where the other was. Adjust the design of the form as follows:
     


    Save and close it

 

 

 

Yugo National Bank

 

 

  1. Open the Yugo National Bank and, in Design View, create a new table with the following fields:
     

Field Name

Data Type

Additional Information

ChargeReasonID

AutoNumber

Primary Key
Caption: Charge Reason ID

ChargeReason

 

Caption: Charge Reason

Description

Memo

 

2.      Save it as ChargeReasons and close it

  1. Using AutoForm, generate a form based on the ChargeReasons table and save it as ChargeReasons before closing it
     

  1. Open the ChargeReasons form and create the following records
     

Charge Reason ID

Charge Reason

Description

1

Monthly Charge

Applied every month to all accounts

2

Overdraft

Applied if a customer's account remains negative for 72 hours

5.      Close the form

 

13.

Managing Relationships

 

 

 

Numeric Fields Referencing

 

 

Most of your data entry will be performed on forms. This is done to protect your tables from (even unintentional) corruption. This means that, during table design, you should be aware of what table is doing what and why. The combo boxes we have created so far provide a good mechanism for data entry but as long as you know what data a field is holding, you don't necessarily have to create these combo boxes on tables. The only piece of information a foreign key field really needs is a number: the number is what connects it to the Primary Key field of the originating table. Therefore, once you understand the use of relationships and lookup fields, you can simply create a numeric field that acts as a liaison between two tables.

 

Practical Learning: Creating a Numeric Lookup Field

 

 

  1. Open the Video Collection database you started in the previous lesson
  2. From the Tables section of the Database window, open the Videos table in Design View
  3. Right-click CopyrightYear and click Insert Rows
  4. In the new empty field, type DirectorID and set its Data Type to Number
  5. In the lower section of the view, make sure the Field Size is set to Long Integer. In the Caption field, type Director
  6. Save the table and switch to Datasheet View
  7. Without closing the Videos table, from the Tables section of the Database window, double-click the Directors table to open it
  8. Display both tables so the Directors table is on top and in the background while the Videos table is at the bottom
  9. Then enter the number of the DirectorID from the Directors table to the corresponding Director in the Videos table
     
  10. Close both tables

 

Relationship Diagrams

 

 

The concept of relational database insures data reliability on the concept of data moving from one source to another. There are many goals behind this theory. Data in your resources needs to be as much accurate as possible. Provided your database is made of various objects, mainly tables, you should avoid any redundancy possible. In other words, data from one source should be unique. To accomplish these goals, you interrelate the various components of your database, namely tables (remember, data in your database depends on, or is originating from, tables).

 

In our earlier illustration, we saw that a foreign key field created in a table acts as an ambassador. To make this effective, a formal relationship must be created between that field and the primary key field of the table it represents. There should be some type of link between both fields.

When you are creating a Lookup field, you are indicating that the value entered in this particular field will come from another table, and you specify the originating table. The originating table is the parent table. The target table is the child table.

The reason you established Primary Keys in your tables is because these are the fields used to build relationships between tables. They are used to verify the uniqueness of data. Also, they avoid that data in relationships be mixed. You can build a reliable relationship only between data of the same kind. We also saw that, to make it easy to recognize the primary key of a parent table and the foreign key of a child table, both fields should have the same name, although this has little to do with the database itself: as long as both fields have the same data type, the relationship can be created.

Tables and fields relationships are created and managed in a special window called the Relationship window. To display it, on the Database toolbar, you can click the Relationships button. Alternatively, on the main menu, you can click Tools -> Relationships. After clicking one of those, if no relationship exists among the tables in the current database, the Show Table dialog box would come up, asking you to select the tables whose relationship(s) you want to create. If at least one relationship has been created between two tables, the Relationship window would come up and display that relationship or the already existing relationships. In this case also, if a table of the current database is not represented in the window, to add it, display the Show Table dialog box, select the table, click Add and click Close. You can create a relationship only between two tables that are present on the Relationships window. This means that even if a table is part of your database and you want to link it to another table (of your database), if the table has not been added to the Relationships window, you cannot create or manage its relationship to another table. Of course, there are other ways you can create relationships without using the Relationships window but the Relationships window gives you advanced and detailed means of creating and managing relationships.

When the Relationships window is displaying, a new menu group is added to the main menu: it is the Relationships. To establish a relationship that does not yet exist between two tables, you can drag the primary key from the parent table to the foreign key of the desired table. If drag it accurately, the relationship would be acknowledged and you can just click Create to make it formal. If you dropped the primary key on the wrong field, you would have time to select the appropriate fields in the Edit Relationship dialog box.

After working with the Relationships window, you can close it. You would be asked to save it in order to keep the relationship(s) created.

 

Practical Learning: Establishing Tables Relationships

 

 

  1. Open the Music Collection1 database
  2. On the Database toolbar, click the Relationships button
    The Show Table property sheet comes up. From here, you will specify what tables (or queries) will be used when building your relationship (s):
     

  1. Click MusicCategories once and click the Add button 
  2. Double-click the MusicAlbums
  3. On the Show Table dialog box, click the Close button
  4. To add another table as if we forgot it, right-click an empty area in the Relationships window and click Show Table…
  5. In the Show Table dialog box, click AlbumTracks. Then click Add and click the Close button
  6. Arrange the layout of your Relationships window so that the MusicAlbums table is in the middle of the MusicCategories table on its left and the AlbumTracks table on its right.
    The originating table uses its Primary Key and associates it to the field you choose in the target table. The target field is referred to as the Foreign Key
  7. Drag the MusicCategoryID field from the MusicCategories table and drop it on top of the MusicCategoryID field in the MusicAlbums table:
     

 

  1. The Edit Relationship dialog box comes up. This allows you to confirm creating a relationship
    Click the Create button to create the relationship
    Now you have a line relating these two tables
  2. Drag any field from the MusicAlbums table and drop it on top of any field in the AlbumTracks as if you missed the target
     

  1. Once again, the Edit Relationship dialog box comes up
    On the dialog, under the left Table/Query, click the field that is selected to display its combo box. In that left combo box, select AlbumID and press Tab
  2. Under Related Table/Query, click the field that is selected and click the arrow of its combo box
  3. Select AlbumID
     

  1. Click Create
  2. To add another table that we failed to include to the diagram, on the main menu, click Relationships -> Show Table…
  3. In the Show Table dialog box, double-click Artists and click Close
  4. Position the new table to the top left section of the Relationships window and move the MusicCategories table under it
  5. To create a new relationship, on the main menu, click Relationships -> Edit Relationship…
  6. On the Edit Relationship dialog box, click Create New…
  7. In the Create New dialog box, click the arrow of the Left Table Name combo box and select Artists. In the Right Table Name combo box, select MusicAlbums. In the Left Column Name combo box, select ArtistID. In the Right Column Name combo box, select RecordingArtistID
     

  1. Click OK
  2. In the Edit Relationship dialog box, click Create
     

  1. On the Relationship toolbar, click the Save button and close the Relationships window
  2. Now we will include a table without using the Relationships window. 
    Open the MusicAlbums table in Design View
  3. Click the Format field to give it focus
  4. Press Tab, type L and press F6
  5. When the first page of the Lookup Wizard comes up, accept the first radio button and click Next
  6. Click Formats and click Next
  7. In the list, double-click AlbumFormat and click Next:
     

  1. Agree to let Microsoft Access Hide The Primary Key and click Next
  2. Accept the label as Format and click Finish
  3. Accept to save the table
  4. Save the table and switch to the Datasheet View to verify that the Format field has a combo box and does not allow any value that is not coming from the Formats table
  5. Specify the appropriate formats
     

  1. When you have finished, close the MusicAlbums table
  2. To open the Relationships window, on the main menu, click Tools -> Relationships…
    Notice that, this time, the Relationships window opens because some relationships had already been created among tables
  3. On the main menu, click Relationships -> Show Table…
  4. On the Show Table dialog box, double-click Formats and click Close
  5. Notice that a joining line is created between the MusicAlbums table and the Formats table
     

  1. Save and close the Relationships window

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Note

This feature is not available in MS Access 97. Therefore, if you are using that version, create the relationship as done above.

 

MOUS Topics

 

 

S3

Establish tables relationships

S13

Modify tables using Design View

 

Exercises 

 

 

Watts A Loan

 

 

  1. Open the Watts A Loan database. Start a new table in Design View and create it with the following fields:
     

Field Name

Data Type

Additional Information

LoanProcessingID

AutoNumber

Primary Key
Caption: Loan Processing ID

EmployeeID

Number

Caption: Processed By

DateProcessed

Date/Time

Format: Short Date
Input Mask: 99/99/00
Caption: Date Processed 

CustomerID

Number

Caption: Account Number

TypeOfLoanID

Number

Caption: Type of Loan

LoanAmount

Currency

Loan Amount

InterestRate

Number

Field Size: Double
Format: Percent
Caption: Interest Rate

PeriodicPayment

Currency

Caption: Periodic Payment

FirstPaymentDueDate

Date/Time

Format: Short Date
Input Mask: 99/99/00
Caption: 1st Payment Due Date

RegularPaymentsDueOn

 

Caption: Regular Payments Due On

NumberOfPayments

Number

Field Size: Integer
Caption: Number of Payments

Notes

Memo

 

2.      Save it as LoanProcessing and close it

  1. Open the Relationships window and create the relationships as follows:
     

     
    If you are using Microsoft Access >= 2000, print the Relationships diagram and save it as Watts A Loan Map

 

Yugo National Bank

 

 

  • a) Open the Yugo National Bank and create a new table in Design View with the following fields:
     

Field Name

Data Type

Additional Information

TransactionID

AutoNumber

Primary Key
Caption: Transaction ID

Processed By

 

 

Account Number

 

 

Transaction Type

 

 

·         b) Save the table as Transactions
c) Use the Field Builder to add the TransactionDate field of the Transactions sample table under the other fields
d) Use the Field Builder to add the TransactionNumber field of the Transactions sample table under the other fields
e) Use the Field Builder to add the DepositAmount field of the Transactions sample table under the other fields
f) Use the Field Builder to add the WithdrawalAmount field of the Transactions sample table under the other fields
g) Use the Field Builder to add the ServiceCharge field of the Transactions sample table under the other fields
g) Use the Lookup Wizard for the Processed By field. Select the LastName, the Title, and the CanCreateNewAccount fields of the Employees table. Keep the label as Processed By
h) Use the Lookup Wizard for the Account Number field. Select the AccountNumber and the AccountName fields of the Customers table. Keep the label as Account Number
i) Use the Lookup Wizard for the Transaction Type field. Select the TransactionType field of the TransactionTypes table. Keep the label as Transaction Type
j) Add a new field at the end of the table and name it Charge Reason. Use the Lookup Wizard for the Charge Reason field. Select the ChargeReason field of the ChargeReasons table. Keep the label as Charge Reason
k) Add a new field under the others. Name it Notes and set its Data Type to Memo
Save the table and close it

Yugo National Bank - Transactions Table

 

14.

Referential Integrity

 

 

 

Cascades

 

 

Introduction

 

 

At this time, we know that there is useful functionality to creating relations between tables as they allow the user to select existing information instead of typing it. This flow of information brings up issues about what happens if data that exists in a parent table gets deleted while such information has been made available to another table.

When manipulating data that is in a relationship, it is very important to make sure that data keeps its accuracy from one table or source to the other. To accomplish that goal, some rules must be established to “watch” or monitor the flow of information between two tables. Data or referential integrity is used to check that two tables are related through one field on each table used as the primary key and the foreign key, data entered in the foreign key of a child table must exist in the parent table or it would be rejected, only two fields of the same data type are used to establish a relationship between two tables, the tables involved in the relationship belong to the same database.

 

Cascades on Related Records

 

 

After creating a relationship between two tables, you must then make sure that when data changes in the parent table, this change is reflected in the child table. For example, if a bank customer changes her last name after getting married or after a divorce, you should be able to change her name in one object (table) and the related objects, such as the one used to process her transactions would receive the changes without your having to make the change on each object (table). In the same way, when data is deleted, the objects that are related to it must also have that data deleted.

To enforce the rules of data integrity, Microsoft Access provides three check boxes in the Edit Relationship dialog box. First, if you want Microsoft Access to monitor data flow, you can click the Enforce Referential Integrity. This would make available two other check boxes.

 

The Direction of a Relationship

 

 

The One-To-Many Relationship

 

 

As mentioned already, a relationship between two tables allows one table, the parent, to make its information available to another table (the child). Because in this case the user is asked to select information, it is likely that the same record of a parent table can be tied to various records in the child table. For example, one customer at a bank can deposit an amount of money today. The same customer can make another deposit tomorrow and even another deposit next month. In such a case, the relationship between the tables would show various entries of the same customer’s account number in the object (table) used to deposit money but with different transactions. This type of relationship is known as one-to-many because one entry in the parent table can result in many entries in the child table.

To create a one-to-many relationship, check all three referential integrity check boxes and click OK or Create. The parent table would have a one on its side of the joining line. The child table would have the infinity symbol on its side of the joining line.

 

Practical Learning: Editing Relationships

 

 

  1. Open the Music Collection1 database you were working on in the previous lesson
  2. To display the Relationships window, on the main menu, click Tools -> Relationships…
  3. To control the relationships, on the Relationships window, click the joining line between MusicCategories and MusicAlbums. Notice that it becomes thicker than the others
  4. On the main menu, click Relationships -> Edit Relationship…
  5. Click the Enforce Referential Integrity check box.
    Now, the database would like to know how you would handle data updating and deletion
  6. Check the other two check boxes:
     

  1. Click OK
  2. In the Relationships window, right-click the joining line between the Artists and MusicAlbums tables:
     

  1. Click Edit Relationship... from the popup menu
  2. Click all the three check boxes and click OK
  3. In the Relationships window, double-click the joining line between MusicAlbums and AlbumTracks
  4. In the Edit Relationship dialog box, click all three check boxes and click OK
  5. Using one of the above three techniques, configure the joining line between the MusicAlbums and the Formats tables for a one-to-many relationship that performs both cascade update and cascade deletes
     

  1. Save the relationships window and close it

 

The Many-to-Many Relationship

 

 

Although one-to-many is the most common type of relationship applied on tables, in some databases, you may need to create a relationship in which many records from one table A can have many related records in another table B and vice versa. This type of relationship is known as many-to-many. For example, in our Video Collection database:

  • It is possible to have one video that has many actors. In this case, if we had created a field to receive actors in the Videos table, we would enter many names of actors in that one field but this type of database would not be professional
  • At the same time, one actor can have participated in many videos. In this case, if we had created a field to enter the titles of videos in the Actors table, the field would have too many entries, making the table unprofessional

To implement this type of relationship, you can create what is called a junction table. A junction table is a table whose main purpose is to bring together fields from other tables, creating a type of cross relationship for the necessary fields. A junction table can be very helpful for data analysis and sub-forms/sub-reports:

A junction table is usually made of three or four fields (usually not less than three and usually not more than four; a classic junction table has only three fields). The first field, almost less engaged, is used as the primary key, the same type of field almost every table has. The other fields hold data that would emanate from other tables.

You can create a junction table either in Datasheet View or in Design View:

  • To create a junction table in Datasheet View, you use the Lookup Column menu that would call the Lookup Wizard. From the Lookup Wizard, select the table that holds the desired field, then select the field itself, and click Finish. After adding the first column, repeat the same steps for each needed field
  • To create a junction table in Design View, set the field's data type to Lookup Wizard and proceed the same way you would for the Lookup Column

You can also switch to either view to create a junction table. In other words, you can create one field in one view and create the other field in the other view.

 

Practical Learning: Creating Junction Tables

 

 

  1. Open the Video Collection database you started in Lesson 12
  2. To create a new table, on the main menu, click Insert -> Table
  3. From the New Table dialog box, double-click Design View 
  4. Type VideoActorID as the name of the first field
  5. Set its Data Type to AutoNumber
  6. Right-click the VideoActorID name and click Primary Key
  7. Save the table as VideosAndActors
  8. Click the empty field under VideoActorID, type ActorID then press Tab, type L and press F6
  9. In the first page of the Lookup Wizard, make sure the first radio button is selected and click Next. 
  10. On the second page of the wizard, make sure Actors is selected and click Next
  11. In the Available Fields list, double-click Actor and click Next twice
  12. Change the field's label to Actor/Actress and press Enter
  13. When asked to save the table, click Yes
  14. Switch the table to Datasheet View
  15. In Datasheet View, right-click Actor/Actress and click Lookup Column…
  16. In the first page of the Lookup Wizard, make sure the first radio button is selected and click Next
  17. From the list of tables, click Videos and click Next
  18. From the Available Fields, double-click Title to select it and click Next
  19. Make sure the Hide Key Column check box is marked and click Next
  20. Change the label to Video Title and click Finish
  21. Switch the table to Design View
  22. Set the Description of VideoID to The title of a video
  23. Set the Description of ActorID to An actor or actress who participated in this video
     

  1. Save the table and switch it to Datasheet View
  2. To perform data entry, on the Video Title column, click the arrow of the combo box and select A Few Good Men
  3. Then, on the Actor/Actress column, click the arrow of the combo box and select Jack Nicholson
  4. In the same way, complete the table as follows:
     
  5. Close (and if necessary save) the table. 
  6. To open the Relationships window, on the main menu, click Tools -> Relationship... 
  7. Observe the names of tables on the window
    Right-click an empty area of the Relationships window and click Show Table... 
  8. On the Show Table dialog box, double-click Directors table. Also, if there is a table on the Show Table property sheet that is not displaying in the Relationships window, add it
  9. To close the Show Table property sheet, click the Close button
  10. Position the VideosAndActors table between the Actors and the Videos tables
  11. Drag DirectorID from Directors and drop it on top of DirectorID in Videos
  12. Check the Enforce Referential Integrity check followed by the Cascade Update Related Fields and Cascade Delete Related Fields check boxes
     

  1. Click Create
  2. As done previously, double-click each joining line and enforce its reference integrity to both update and delete records in the Edit Relationship dialog box
     

  1. If you are using Microsoft Access 2000 and later, on the main menu, click File -> Print Relationships...
     
  2. Click the close button. When asked to save the report, click Yes. Change the name of the report to Video Collection Layout and click OK
  3. Close the Relationships window (in Microsoft Access 97, if you are asked to save the window, click Yes). 

 

The One-to-One Relationship

 

 

A one-to-one relationship is the type of junction between two tables A and B so that one record in a table can have only one corresponding entry in table B and vice versa. Because this is similar to one table of records, this type of relationship is hardly used since you can as well simply create one table.

 

Subdatasheets

 

 

A sub datasheet provides a technique of creating or displaying relationships in a table in a Datasheet View. It can help you or the user see information that is stored in another table. For example, when using a music collection database, it can should the music tracks that are part of an album by displaying an album in a table as long as a relationship has been created and configured.

To use a sub datasheet, open a table or query in Datasheet View and click the + button on the first column of the desired record. Here is an example:

Note

The subdatasheet is not available in Microsoft Access 97

 

 

Practical Learning: Using a Sub Datasheet

 

 

  1. Open the Music Collection database
  2. On the Database Window, from the Tables section, double-click the MusicAlbums table
  3. Click the + button on the left of Tribute
     
  4. Notice that the tracks of the music album display
  5. To perform data entry, click the + button of the One Bright Day record
  6. Click the empty field under # then type 1 and press Enter
  7. Complete the list of tracks as follows:
     

#

Track Title

Length

1

Black My Story (Not History)

04:16

2

One Bright Day

04:12

3

Who Will Be There

04:10

4

When The Lights Gone Out

04:09

5

All Love

04:39

6

Look Who’s Dancing

05:00

7

Justice

04:12

8

Love Is The Only Law

04:07

9

Pains Of Life

03:46

10

Urban Music

02:54

11

Problems

04:02

12

All You Got

04:19

13

When The Lights Gone Out (Jamaican Stylee)

04:52

  1. After viewing the table, close it

 

MOUS Topics

 

 

S30

Display related records in a subdatasheet

S34

Enforce referential integrity

S45

Print database relationships

 

Exercises 

 

 

Watts A Loan

 

 

  • Open the Watts A Loan database and configure the cascading of relationships as follows:
     

     
    Save and close the Relationships window

 

Yugo National Bank

 

 

  • Open the Yugo National Bank database and open its Relationships window. Enforce the cascades on relationships as follows and save it:
     

     
    If you are using Microsoft Access >= 2000, print the Relationships dialog box and save its report as YNB Main Diagram

 

15.

Introduction to Data Analysis

 

 

 

Techniques of Sorting Records

 

 

Introduction

 

 

Data analysis provides the user with the ability to examine a database's records and the overall behavior of its objects. Data analysis is performed on tables, queries, and/or forms. There are two main aspects involved with data analysis: what you provide to the users and what the users may decide to do with data at their disposal. An intermediate to advanced user of Microsoft Access will know how to perform some, most, or all of the operations we will review. In some other cases, you may want to create 

 

objects such as forms and/or reports that isolate records instead of showing all records. These types of forms and reports can be based on a query or a SQL statement. In some other cases, you can create queries that your users would run to get a fixed list of records based on a rule of your choice. For these and many other reasons, you should be aware of what your users can do and what they should not do.

 

Record Sorting on Tables

 

 

By default, if you have a first field on a table to register incremental numbers (AutoNumber) as the user enters records, the records are organized in the order they were entered. They typically follow the ordinal numbers defined in the first field, as numbers are counted from the lowest to the highest. One way you can change this order is to rearrange the list of records based on a field of your choice. Rearranging the order of records is referred to as sorting.

To sort records, you must first select the field that would be used as the reference. To do this, you can click a field under the column of your choice. You have two options. To arrange the list in alphabetical order, you can ask the table to display its records in ascending order. To arrange records in alphabetical order following the field of your choice, you would use the Sort Ascending option, which is available from the main menu (Records -> Sort -> Sort Ascending).

Besides the regular arrangement of records, you can also sort records in reverse alphabetical order. This is done using a column as basis using Sort Descending. Both techniques of sorting are also available when you right-click the desired field on the table.

When you have finished viewing, it is sometimes important to reset the table before continuing unless you want to keep the table sorted.

If you sort records on a column whose fields are not all filled, which means some records are empty, the empty records would display first before the other records start in alphabetical order. This would allow you to find out which fields have not been filled; that is, what records are incomplete or missing. For example, in our students registration form, imagine you want to find out what students do not have the emergency name (which means if something happens, the user wouldn't know who to call) (of course, an alternative would be to make such a field Required), you can sort the emergency name. Here is an example:

For this reason, you can sort records on a field, not because you want to get the alphabetical order, but because you would like to find out what record(s) need(s) to be completed. This could be used to find out what student doesn't have an e-mail address yet.

Besides the sorting of text fields, you can also arrange a list of records by seniority. This is usually done by sorting a date field. In the case of a student list, you can sort records based on the date of birth. When sorting a list of records based on a date, the year is first considered. This means that, if two records have different years, the record with the oldest date would display first (of course, to get the youngest date first, you can sort in descending order). If two dates have the same year value, the month would be considered. The date with the earliest month would display first. If two dates have the same year and the same month, then their day values would be considered.

By right clicking, you can sort any field in the table or form. When a field has a combo box with two values, such as the M/F field for the Gender column, you can sort a Boolean column whose fields are equipped with a check mark. If you sort such a field in ascending order, the True, On, Yes or 1 records would display first, followed by the opposite records.

 

Practical Learning: Sorting Records on Tables

 

 

  1. Open the ROSH database and open the Students1 table in Datasheet View
  2. To view the list of students in alphabetical order based on their last name, click any field under the Last Name column
  3. On the main menu, click Records -> Sort -> Sort Ascending
     
  4. Notice that some students have the same last name
  5. To see a list of students by date of birth starting with the youngest, click any field under the Date of Birth column
  6. On the Table Datasheet toolbar, click the Sort Descending button
  7. To restore the table to its original arrangement, right-click any field under Student ID and click Sort Ascending
  8. Close the table. When asked whether you want to save the table, click No

 

Record Sorting on Forms

 

 

When reviewing forms, we saw that a form can display in Datasheet View, like a table or a query. With that type of form, you can apply the same techniques we used to sort records on a table. If you display a form in its regular and most usual format, where it displays one record at a time, you can still perform the same sorting operations as done on a table. This allows you to view one record at a time.

 

Practical Learning:  Sorting Records on Forms

 

 

  1. In the Database window, click the Forms button and double-click the Students form to open it in Form View
  2. Observe the last name of the first record. To navigate through the records, click the Next Record button a few times
  3. To get to the first record, click the First Record button 
  4. To jump to a specific record, select the number in the Record Number text box and type 42:
     

  1. Press Enter. Notice that the table has jumped to record 42
  2. To navigate backward, click the Previous record button 
  3. To return to the first record, press Ctrl + Home
  4. To organize the student's Last Names alphabetically, click the Last Name field on the form
  5. On the main menu, click Records -> Sort -> Sort Ascending:
     

  1. Notice that the records are arranged alphabetically based on the students last names
  2. To arrange the list of students by age starting with the youngest, click the Date of Birth field
  3. On the Form View toolbar, click the Sort Descending button 
  4. To sort records using the context-sensitive menu, right-click the Gender field and click Sort Ascending
  5. To dismiss the sorting of records, on the main menu, click Records -> Remove Filter/Sort
  6. To sort records based on a Boolean field, we will find out who (students) lives in a single parent home.
  7. Right-click the Single Parent? label or its check box and click Sort Ascending
  8. Navigate through the records. Notice that the records of students who live in a single-parent home display first
  9. When you have finished viewing, to remove the sorting, right-click anywhere on the form and click Remove Filter/Sort 
  10. Close the form

 

Record Filtering on Datasheet and Form Views

 

 

Introduction

 

 

So far, we have built fairly simple queries that consisted of displaying all records that are part of a table. The only thing we were doing was to select the necessary fields. In some circumstances, you may want to set a limit on the number of records to display or make available to the user. To do this, you must create a rule and ask Microsoft Access to apply it to a set of records (also called a Recordset). The rule works like a funnel that decides what to let through and what to retain. The rule is also called a criterion. For example, you can set a criterion that asks a query to consider the list of all students in a school but to restrict the list only to female students.

 

A filter is a criterion or a set of criteria that must be applied to a Recordset to create a list of records that abide by a common rule. Filters can be used to isolate records on a table, a query, a form, or a report. There are differences on the way each type of value handles it.

 

Records Filtering Using Selections

 

 

While sorting is used to rearrange data in alphabetical, incremental, or decremental orders, filtering allows you to isolate data. For example, when you order the Gender column alphabetically, you get a list of girls first (F for Female), then the boys (M for Male). Using a filter, you can create a list that would include only one of these categories.

Fields on a table are organized in categories. For example, in the Last Name, all records are meant to represent a string as people's last name. The content of such a field can be used as a basis for selecting records. It is another way of asking a table to isolate records that share the exact same content. This technique of isolation is referred to as Filter By Selection.

To filter records that display on a data sheet, based on a selection, you can first click a field that would be used as the basis. Then on the main menu, you can click Records -> Filter -> Filter By Selection. Imagine you have a list of videos in a Video Collection database and stored in a table named tblVideos:

Imagine you want to have a list of only movies that are rated R. To do that, you can click an R field and filter by selection:

 

Unlike the sorting techniques, filtering hides data. In order to execute another filter on all records, you must remove the previous filter, unless, as we will see shortly, you want to combine filters. The context menu provides the same options available on the toolbar.

You can also filter records using a Boolean field that is equipped with check boxes. For example, on the Single Parent? column of the Students table, you can ask the table to show only the list of students who live in a single parent house. To do this, you can filter by selecting a record that is checked.

 

Practical Learning:  Filtering Data By Selection

 

 

  1. Open the ROSH database and, from the Tables section of the Database window, open the Students1 table
  2. To filter records by selection, under the Gdr column, click any field that has M 
  3. On the main menu, click the Records -> Filter -> Filter By Selection
  4. Scroll down in the list and notice that the table displays only male students
  5. Also notice that the bottom section of the table displays Filtered
  6. To remove the filter, on the main menu, click Record -> Remove Filter/Sort
  7. To view only the records whose ZIP Codes are known, click any field under ZIP Code
  8. On the Table Datasheet toolbar, click the Filter By Selection button
  9. Notice that the list displays only records that have an entry in the ZIP Code
  10. To remove the filter, on the Datasheet toolbar, click the Remove Filter button
  11. Close the Students1 table. When asked whether you want to save the changes, click No
  12. On the Database window, click the Forms button and double-click the Students form
  13. To get only the list of girls, click the Next Record button a few times until a record displays F in the Gender field
  14. Right-click F and click Filter By Selection
  15. Navigate through the records and notice that the form now displays a list of only female students. To indicate this filter, the number of records displays (Filtered):
     

  1. To refresh the form, on the main menu, click the Records -> Remove Filter/Sort
  2. Navigate to a field whose Single Parent? check box is checked
  3. For an example of filtering a Boolean field, right-click a Single Parent? field (one that is checked) and click Filter by Selection
  4. Notice that the form is now displaying a list of only the students who live in a single parent home
  5. To remove the filter, right-click anywhere on the form and click Remove Filter/Sort

 

Filter By Exclusion

 

 

Instead of using a field's content as a basis for inclusion, you can ask the table to deny or hide the records that respond to a certain field. This is referred to as filtering by exclusion. In Microsoft Access, this is done using Filter Excluding Selection. Imagine that, on your Videos table, you want to get a list of movies that are not rated R, you can right-click an R field in the Rating column and click Filter Excluding Selection.

 

Practical Learning:  Filtering Records By Exclusion

 

 

  1. Navigate to a record whose State field displays MD
  2. To get a list of the students who live outside of Maryland, right-click MD in the State field and choose Filter Excluding Selection
  3. Notice that the form displays a list that excludes MD 
  4. When you have finished viewing, on the Form View toolbar, click the Remove Filter button 
  5. Close the Students form

 

Filter By Form

 

 

 

The techniques we have used so far to analyze our data consisted of looking for a particular field content as a basis for our filtering. Microsoft Access provides another technique that allows you to select a criterion from an empty field. Using this technique, the whole table is emptied and all records get hidden. You can then select your criterion from the column of your choice. Although the fields appear empty, each column equips its first and only field with a combo box that displays a list of all records of that column, thereby allowing you to select, which one of the fields responds to your choice. This technique is referred to as Filter By Form.

 

Practical Learning:  Filtering By Form

 

 

  1. From the Tables section of the Database window, open the Students1 table
  2. On the main menu, click Records -> Filter -> Filter By Form
  3. Click the empty box under Gdr.
    To get a list of female students, click the arrow of the Gender combo box and click F 
  4. To apply the filter, on the main menu, click Filter -> Apply Filter/Sort 
  5. Scroll down in the list and notice that the table displays only girls