MS Access Fundamentals

Embed Size (px)

Citation preview

MS Access FundamentalsIntroduction to Microsoft Access Introduction to Data Sheets Intro to Forms and Reports Database Fields On Sheet Managing Data Fields Data Fields on Forms and Reports Data Field Design Properties of Data Fields Operators and Operands Introduction to Data Types Using Data Types Introduction to Relationships Managing Relationships Referential Integrity Introduction to Data Analysis The Structured Query Language Queries and Relationships Exploring Data Analysis Data Analysis With Charts Formatting Charts Action Queries Data Maintenance, Import/Export Tables and Queries Aesthetics Characteristics of Forms Windows Controls Types of Forms

1

Subforms Introduction to Expressions Controls and Expressions Built-In Functions Series-Based Functions Domain-Based Functions Business-Based Functions Finance-Based Functions

Introduction to Microsoft AccessMicrosoft Access LaunchingIntroductionMicrosoft 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:

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:

2

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.

Microsoft Access ShortcutsWhenever 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 Shortcut1. Right-click on an empty area of the Desktop -> New -> Shortcut

3

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 Access2000, 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

4

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

The Title Bar1. As a regular Windows application, Microsoft Access shares some characteristics that arecommon 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

5

Minimizes the window Maximizes the window Restores the window Closes the window

The Main Menu1. Under the title bar, there is a horizontal list of words. This list is made of items such asFile, 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

6

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 T Alt, G Ctrl + H Ctrl + Shift + E Means Press the T key Press and release Alt. Then press G Press and hold Ctrl. While you are still holding Ctrl, press H once. Then release Ctrl Press and hold Ctrl. Then press and hold Shift. Then press E once. Release Ctrl and Shift

The ToolbarsUnder 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:

7

You could also create your own toolbar.

The Status BarThe 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 File1. Click Create 2. When the Database Wizard dialog box comes up, click Finish

Opening a DatabaseUnlike 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 Database1. Open Windows Explorer or My Computer and locate the folder that contains the resources that accompany this ebook. 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

8

4. Click Grier Summer Camp

5. Click Open

Overview of Database ObjectsThe Database WindowAfter 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

9

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 windows 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 windows toolbar. To do this, you can click the object to select it. Then, on this toolbar, click the Delete button. The Database windows 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:

10

Database Objects: TablesA 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 Table1. 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: QueriesA 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 Query1. 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 toopen it:

NotesQueries 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.

11

3. After viewing the query, to close it, click its Closebutton

Database Objects: FormsTables 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 Form1. On the Database Window, click Forms

2. Double-click MembersByGender

3. After viewing the form, click its Close button dismiss it

Database Objects: ReportsA 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.

12

Practical Learning: Opening A Report1. On the Database Window, click the Reports button

2. Double-click Camps

3. After viewing the report, click its Close button

Database Objects: PagesStarting 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.

Practical Learning: Data Access Pages1. On the Database Window, click the Pages button

2. Double-click Camps

3. After viewing the page, click its Close button

MacrosWhen 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.

Modules13

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 Basic1. 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 awindow 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 HelpContext-Sensitive HelpContext-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 Whats 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 Help14

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 Whats This button

7. Click the list box in the middle right side of the dialog

15

8. After viewing help, click the Whats This button again and click the combo box, in the bottomright side of the dialog box

9. After viewing help, press Esc and click Cancel

The Office AssistantThe 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 Assistant1. 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

16

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 redisplays. 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 HelpIt 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 HelpAlthough 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

17

categories.

Microsoft Access ExitSince 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

Introduction to Data SheetsCreating a DatabaseThe Database WizardMany 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. 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..

Practical Learning: Creating a Database Using a Sample1. 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

18

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 typeRockville 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 box12. Click Next

13. For the style of the screen display, choose International to preview one of the samples andclick Next

19

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 usat 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

20

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 PropertiesYour 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 Access1. 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 this ebook 8. Click the Rockville Techno icon and click OK

9. Accept all the other defaults:

21

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 this ebook

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. 22

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 toconduct 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 FundamentalsThe Table WizardMicrosoft 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

23

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:

24

Practical Learning: Using the Table Wizard1. 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 theTables tab, click New and double-click Table Wizard). The Table Wizard starts In the Sample Tables list box, scroll down and click Assets

3. Click the Business radio button if necessary 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 RemoveOne 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 theRename 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 CompanyAssets18. Click Next twice and click Finish

19. To close the CompanyAssets table, click its system Close button 25

Data Entry on TablesData 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 Entry1. 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 Printer Computer Laptop Printer Digital Camera Computer

Make HP IBM Gateway Xerox Olympus IBM

Model

Date Acquired 10/08/2002 12/05/2002 10/22/2002 11/06/2002

Purchase Price 1950.95 1035.00 2095.95 1250.55 450.75 1055.55

Notes B/W Printer Business Notebook Color Printer

LaserJet 4200dtn 10/08/2002 NetVista M42 200XL Phaser 8200 C-50

ThinkCentre S50 10/08/2002

26

7. Close the CompanyAssets table

8. On the Database window, right-click the Payment Methods table and click Open9. Complete it as follows: Payment Method ID Payment Method 1 Check 2 Cash 3 Money Order 4 Visa 5 Master Card 6 American Express Credit Card? No No 0 1 -1 58

10. Notice that the 0 value changes into No and any other number changes into Yes

11. To close the Payment Methods table, click its system Close button12. On the Database window, double-click the Employees table to open it 13. Click the first empty field under Last Name, type Phillips and press Enter

14. Perform data entry, skipping other fields15. Close the table after performing data entry

Table PrintingThe 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 Tables1. 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 button4. To print the list of the companys 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

27

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 FundamentalsData Entry on a QueryA 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 Query1. 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: Date Acquired 10/08/2002 12/05/2002 10/22/2002 11/06/2002 Purchase Price 1950.95 1035.00 2095.95 1250.55 450.75 1055.55 Ctrl + ' Business Notebook Color Printer

AssetType Printer Computer Laptop Printer Digital Camera Computer Computer Ctrl + '

Make HP IBM Xerox

Model

Notes B/W Printer

LaserJet 4200dtn 10/08/2002 NetVista M42 Phaser 8200

Gateway 200XL

Olympus C-50 IBM Ctrl + ' Ctrl + '

ThinkCentre S50 10/08/2002 Ctrl + ' Ctrl + ' Ctrl + '

10/20/2002 1120.55

4. After using the query, close it

5. To create a query of selected information of employees, on the main menu, click Insert ->Query

28

6. In the New Query dialog box, click Simple Query Wizard and click OK 7. In the first page of the wizard, in the Tables/Queries combo box, select Tables: Employees

8. In the list of Available Fields, double-click FirstName, LastName, Title, and BillingRate9. Click Next twice

10. Change the Title of the Query to Employees Pay Information and click Finish11. After viewing the result of the query, close it

Query PrintingLike 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 Query1. 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 clickrelease Shift

8. On the main menu, click File -> Print and, on the Print dialog box, click Selected Record(s) 9. Click OK to print

29

10. After using the query, close it.

ExercisesTenley Associates1. Start a new database using the Database Wizard and based on the Expenses sampledatabase

2. Name it Tenley Associates 3. For the Information About Employees, add Department Name, Email Name, HomePhone, 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 tableand enter the following expenses: Expenses Category ID Expenses Category 1 Office Equipment 2 Car Rental 3 Transportation 4 Customer Entertainment 5 Other 10. Print all records on the table and close it Expense Account# 102 104 105 108 112

11. Open the Employees table and fill it up with the following values, ignoring those notmentioned:

First Name James Alexandra Walter Bertine

Last Name Bidds Roberts Hoaks Baugh

Title Accountant Sales Manager Manager

Home Phone (301) 725-4570 (410) 727-0982 (301) 912-2129

Sales Representative (410) 521-2850

12. Close the table

13. 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

14. Close the query and print all of its records without opening it

15. Using the Employees Contact Information query, print only the second and thirdrecords of employees

16. 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),

30

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 2 Sales 3 Accounting Including all personnel from Management Including all sales representatives and managers

Introduction to Forms and ReportsForms FundamentalsIntroductionAs 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.

AutoFormThe 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 AutoForm1. 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 31

Information query to select it

3. On the Database toolbar, position the mouse on the New Object button. If the tool tipdisplays 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 button5. Accept the suggested name for the form by clicking OK 6. Then close the form

The From WizardAs 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 doubleclick 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:

32

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.

33

The 4th page allows you to name the form.

Practical Learning: Form Wizard - Columnar1. The Rockville Techno database should still be opened On the Database Window, click the Forms button 2. On the Database Windows toolbar, click New 3. On the New Form dialog box, click Form Wizard

4. From the combo box, select the CompanyAssets

5. Click OK

6. Click the Select All Fields button7. 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 FinishAn automatic form is created for you

11. To close the form, click its Close button

Data Entry on a FormData 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 keyboards

34

arrow keys can also be used to move among fields.

Practical Learning: Form Data Entry1. The Rockville Techno database should still be opened and the Forms button should beselected. 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, 35

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, toprovide 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 networkcards on the receptionist and Ms. Maureen's workstations

36

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 onRegular 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 rightaway. 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 PrintingAlthough 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

37

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 Forms1. 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 buttonthe printer and starts printing 3. Close the Projects form and close the Clients form 4. On the Database Window, double-click Employees

. Notice that the job goes straight to

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 button8. 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 buttonVaughn (even though the record # still displays 2) 14. Release Shift 15. On the main menu, click File -> Print

twice to display the record of Lester

16. On the Print dialog box, click the Selected Record(s) radio button and click OK17. Verify that records from 2 to 4 have been printed 18. Close the Employees form

Reports FundamentalsAutoReport38

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 AutoReport1. 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 WizardMicrosoft Access can help you create a more elaborate report where you would use one of the

39

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 Wizard1. 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 button5. 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 Enter12. Scroll down in the report to view the records and close the report

Report PrintingAs 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 Report1. On the Database window, click the Reports button

40

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

ExercisesTenley Associates Company Expenses1. Open the Tenley Associates database 2. Use the Form Wizard to create a Columnar form based on the Employees table andincluding 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 theExpense Details table and save it as Expense Details

4. Fill the Employees form up with the following values, ignoring those not mentioned:Last Name Bidds Roberts Hoaks Baugh Department Accounting Sales Sales Administration Work Phone (202) 266-5022 (202) 266-5022 (202) 266-5022 (202) 266-5022 Extension 2422 2408 2412 2418

5. Print the Employees form

6. Using the Report Wizard, create a Columnar report based on the Expense Categoriestable, including all fields and using the Corporate style. Save the report as Expense Categories and print all of its records Employees Contact Information query. Save the report as Employees Contact Information and print all of its records

7. Using the AutoReport from the Database toolbar, create a report based on the

Database Fields on SheetIntroduction to Data FieldsA Database From ScratchStarting a database from scratch allows you to create and add its different parts as needed.

41

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 Database1. 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 MicrosoftAccess 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 yourdatabase, it requires a name Change the name of the file to Red Oak High School

5. Locate the Exercises folder from the parent folder of this ebook and display it in the Save combo box 6. Click Create to create the new database file.

Database Object and FieldsA 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 FieldsTable LayoutTo 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

42

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 View1. To create a new database, on the main menu, click File -> New (or File -> NewDatabase 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 Cream4. 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 BarA table is a rectangular window. icon . The table icon provides the table. The middle section of popup windows, the right section On top, it presents a title bar. The title bar is made of a table's a menu that allows you to minimize, maximize, restore or close the table icon is formally called the title bar. Like most regular of the title bar presents the system buttons.

Columns and RowsImagine 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 onedimensional because all of its items fit in one category. In order to create a more significant list, you may want to include these peoples email addresses and probably other related information. If

43

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 Bill James Hermine Khan @Khan.com Email Address [email protected] jamesemail.com (102)399-2893 (101) 447-8384 Cousin Phone Number Relationship Friend

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 CellsAlthough 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 BarsIf 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

44

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 ButtonsThe 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 ViewFields NamesOnce 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 persons 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

45

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 rightclick 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 Fields1. Double-click the header of the first field: Field1. When it is highlighted, type OrderDateand 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 OrderTime5. Right-click Field3 and click Rename Column from the context menu

6. Type Container and press Tab

The Name of a TableLike 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,

46

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 Table1. On the Table Datasheet toolbar, click the Save button to save the current table

2. Type CustomersOrders and press Enter3. You will receive a long message box. Click No

4. To close the table, click its system Close button

Column and Row Maintenance in Datasheet ViewIntroductionA 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 InsertionOne 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 Column1. The Clarksville Ice Cream database should still be opened and the Tables button should beselected 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

47

3. Right-click the new Field1 column header and click Rename Column

4. Type Clerk and click the cell under Container5. 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 Enter8. Enter the following records in the table: Clerk Paulette McIntyre Ralph Ammian Alex Mendy Ralph Ammian 9. Close the table 05/10/2000 OrderDate 05/10/2000 05/10/2000 OrderTime 10:16 AM 10:28 AM 11:35 AM Flavor Vanilla Butter Pecan Vanilla Container Cup Cone Cone