Learning Objectives By the end of this session, students are expected to be able to: 1. How to create a Query 2. Querying a database 3. Retrieving a query 4. Form creation 5. Setting form report and control properties 6. Creating labels on a form or report Query creation QUERIES •You use queries to view, change, and analyse data in different ways. You can also use them as the source of records for forms and reports. The most common type of query is a select query. A select query retrieves data from one or more tables using criteria you specify, and then displays it in the order you want. •MS-ACCESS gives a great deal of flexibility in designing queries with which one can: Choose fields to be included. Choose and sort records. Ask and answer questions about data from an existing table. Perform calculations. Use queries as a source of data for Forms, Reports and other Queries. Modify existing data Creating a select query •With Queries a user asks questions about the data in some existing tables. The question is answered by selecting the data that meets certain criteria. A Criteria is the condition which is used as a basis of selecting the records from your tables. To set a query one must understand how the database data is linked together. The most commonly used queries are the Select Query and the Parameter Query. To create a parameter query On the criteria specify/enter text which will be in square brackets []. The text could include the field name but should always give the field name as part of the text but not the sole text. Save the query and close the design view, then open the query. The computer prompts you with a request to enter or specify the record you wish to access. To use a range of data for a parameter, e.g., Dates, use the expression: "Between"[set your text for first date]"And"[text for end date] Computed fields You perform calculations in a query using: Predefined calculations, called "totals", to compute the following amounts for groups of records or for all the records combined in the query: sum, average, count, minimum, maximum, standard deviation, or variance. A custom calculation to perform numeric, date, and text calculations on each record using data from one or more fields. You need to create a new calculated field directly in the design grid for these types of calculations. Querying a database •There may be times when you wish to see or print only certain information stored within a database. This can be done by completing a 'Query'. Instructions are given so that the program extracts the required information from the table automatically. Click on the Database Window button on the toolbar. This brings a dialogue box onto the screen. Click on the Queries tab, then click on New. A dialogue box headed New Query appears, select Design View and OK. Another dialogue box headed Show Table appears. Click on your table name, click on Add, then click on Close. You are now in Query design view. The box in the top half of the screen lists all the fields in your table. Once you have selected the required fields, if you wish the field to print ensure that a tick appears on the row labelled Show in the query grid underneath each field selected. Clicking on the square makes the tick appear/disappear. To sort in a query click in the sort row under the field name you wish to sort and from the drop down menu select Ascending or Descending. To get the system to look for the information you require you need to enter the appropriate data on the Criteria row below the field that holds the information in the main table. Run the query by clicking on the Run icon on the toolbar. An answer table appears on the screen showing only the records that meet the criteria along with the other selected fields. Save the query by clicking on File and then Save As. The system will have automatically entered. Query 1 (or 2, etc) next to New Name. Print the query if you need to and then click on File and Close. This will close the query and take you back to the database window. Click on the Table tab and then open to return to the main table. querying ranges: - It is possible to be more specific when searching for data, by using the following operators: > Greater than (hold down shift key and then the full stop key) < Less than (hold down shift key and then the comma key) >= Greater than / equal to (hold down shift key and then the full stop key, release the keys and press the equal sign key) <= Less than / equal to than (hold down shift key and then the comma key, release the keys and press the equal sign key). Not equal to (hold down shift key and then the full stop key, and then the comma key). For example, >=10 typed in the Criteria row would find records with values of 10 or more. Retrieving a query Click on the Database Window button on the toolbar. The database window appears. Click on the Query tab - all saved queries will be listed on the screen. Click onto the name of the query required and then on Open. The query will appear on the screen. Forms •You can use forms for a variety of purposes. Most of the information in a form comes from an underlying record source. Other information in the form is stored in the form's design. •You create the link between a form and its record source by using graphical objects •called controls. The most common type of control used to display and enter data is a text •box. You can create a form on your own or you can have Microsoft Access create form for you using a Form Wizard. To create a form •In the Database window, click the Form button. (Or choose Form from the View menu.) •Choose the New button. (Or choose New from the File menu, and then choose Form from the submenu) and a New form Dialog box appears. •In the Select A Table/Query box, select the table or query that contains the data you want to display on the form.(If the form won't contain data, don't make a selection from this list) Click the Blank Form button. Microsoft Access displays the Form window in Design view, where you can create a custom layout as shown below. Form views •Forms have three views: Design view, Form view, and Datasheet view. •To create a form, you work in Design view. Viewing a form in Design view is like setting at a •workbench surrounded is useful tools. To set a form views of a form that includes headers and footers. 1) Open the form that you want to use in Design view. 2) Add the fields that you want to display in the form. 3) Size the detail section of the form. 4) Double -click the form selector to open the property sheet for the form. 5) In the Default View property box, click Continuous/Datasheet/Single Form. 6) Make the same choice in Views Allowed. Setting form, report, and control properties Each control, section, form, or report has property settings that you can change to alter the look or behaviour of that particular item. You view and change properties in a property sheet. •To set properties. •In the forms or report's Design view, select the control, section, form, or report whose properties you want to set. You can select: One or more controls One section Display the property sheet. Click the property whose value you want to set, and then do one of the following: •If an arrow appears in the property box, click it and then choose a value from the list. •In the property box, type the appropriate setting'or expression. Creating a list box or combo box with a wizard On a form or report, you can create a list box or combo box by using a Wizard. A list box or combo box can make data comparison easier, quicker, and more accurate by presenting a scrollable list of values from which you can choose an option. To create a list box or combo box with a Wizard: From the View menu, choose Control Wizards (if the Control Wizards command Does not display a check mark). -Or- In the toolbox, click the Control Wizards tool so that it appears sunken. In the toolbox, click the list box or combo box tool. On the form or report, click where you want to place the list box or combo box. Microsoft Access displays the first Wizard dialog box. Follow the directions in the Wizard dialog boxes. In the last dialog box, click the Finish button to display the list box or combo box in Creating labels on a form or report Labels are unbound controls you use to display descriptive information such as titles, captions or instructions. Use the label tool to create a freestanding label. To create a label: In the form's or report's Design view, the toolbox, and then click the Label tool. To create a label those Microsoft Access sizes as you type, click where you want to start the label, and then type the label's text. To create a label of any size where you want the label to start and, holding down the left mouse button, drag the pointer until the label is the size you want. Then type the text in the control. REPORTS A database report is a document that presents data in a structured way in MS –Access the automated solutions includes auto reports and the wizard reports. A report is an effective way to present your data in a printed format. As the user one has the control over the size and appearance of everything on a report, you can display the information the way you want to see it. Most of the information in a report comes from an underlying table, query, or SQL statement, which is the source of the report's data. Other information in the report is stored in the report's design. To create a report: In the Database window, click the Report button, and then choose the New button. The New report Dialog Box appears. In the Select A Table/Query box, you can either type the name of the table Or query on which to base your report or select a name from the list. (To be the source of data for the report.) Choose the Blank Report button. A blank report appears in Design view Key Points Steps to create a query Querying a database Steps of form creation Create a report from a database Evaluation Explain how to create a query? What are functions of a form? Explain the essence of report? References 1. Access. Retrieved May, 2010 from http://www.gcflearnfree.org/computer/ 2. Cook, L.R. (2001). Computer Fundamentals-Understanding How They Work (1st ed.).Vintage Press. 3. Ed Bott & Carl Siechert. (2001). Microsoft Windows XP Inside-out. 4. Joos, I. Whitman, N. Smith, M. Nelson, R. et al. (2006). Introduction to Computers for Healthcare Professionals (4th ed.). London: Jones & Bartlett’s Publishers International. • Morris M. & Charles, M. (2003). Logol Computer Designer Fundamentals. Prentice Hall