Approved by Curriculum Development Centre 151 Oasis Radiant Computer Science, Book 10 codes. We’ll type each of the valid responses in quotation marks and separate them with the word Or, which lets Access know that this field can accept the response “AL” Or “AK” Or “AZ” or any of the other terms we’ve entered. 4. Once you’re satisfied with the validation rule, click OK. The dialogue box will close. 5. Click the Validation drop-down command again. This time, select Field Validation Message. 6. The Enter Validation Message dialogue box will appear. Type the phrase you want to appear in an error message when a user tries to enter data that violates the validation rule. Your message should let the user know what data is permitted. 7. When you’re satisfied with
Oasis Radiant Computer Science, Book 10 152 Approved by Curriculum Development Centre the error message, click OK. 8. The validation rule is now included in the field. Users will be unable to enter data that violates the rule. Simple validation rules can be written exactly like query criteria. The only difference is that query criteria search for data, while an identical validation rule either permits or rejects data. Working with form Creating forms for your database can make entering data much more convenient. When you create a form, you can design it in a way that works with your database and makes sense to you. In this lesson, you will learn how to create and modify forms. You’ll also learn how to use form options like design controls and form properties to make sure your form works exactly the way you want it to. To create a form: 1. In the Navigation pane, select the table you want to use to create a form. You do not need to open the table. 2. Select the Create tab on the Ribbon, and locate the Forms group. Click the Form command.
Approved by Curriculum Development Centre 153 Oasis Radiant Computer Science, Book 10 3. Your form will be created and opened in Layout view. 4. To save the form, click the Save command on the Quick Access toolbar. When prompted, type a name for the form, then click OK. Design Form Form is the data entry interface. It helps to enter the data into the table like data structure. It helps to edit and review the data stored in the database file also. We can create the form by using different technique like form wizard, import form and the form design options. In this lesson we will learn the process to create form using form design method. Steps: ● Click on Form option from create menu. ● Choose the table that will use to design the form and choose Create menu and click on Form. Now the system will automatically design the form using the fields of the table. ● Now we can view the previous records stored on the table and do some modifications if required. But main objective of the form is to enter the data to the database file.
Oasis Radiant Computer Science, Book 10 154 Approved by Curriculum Development Centre ● Now create the form and save it. Open the form and do data entry in to the database file. Designing Form Using Form Wizards • Click on Create Menu • Choose Form Wizard We will get the dialogue box.
Approved by Curriculum Development Centre 155 Oasis Radiant Computer Science, Book 10 • Now select the required fields to make a form. Choose Next. • Choose Columnar or Tabular style of the form and choose Next. Another dialogue box will display. Now save and Finish to open it. Formatting forms Access offers many options that let you make your forms look exactly the way you want. While some of these options—like command buttons—are unique to forms, others may be familiar to you.
Oasis Radiant Computer Science, Book 10 156 Approved by Curriculum Development Centre Command buttons If you want to create a way for users of your form to quickly perform specific actions and tasks, consider adding command buttons. When you create a command button, you specify an action for it to carry out when clicked. By including commands for common tasks right in your form, you’re making the form easier to use. Access offers many different types of command buttons, but they can be divided into a few main categories: • Record Navigation command buttons, which easily allow users to move among the records in your database • Record Operation command buttons, which let users do things like save and print records • Form Operation command buttons, which give users the ability to quickly open or close a form, print the current form, and complete other actions • Report Operation command buttons, which offer users a quick way to do things like preview or mail a report from the current record To add a command button to a form: 1. In Form Layout view, select the Form Layout Tools Design tab and locate the Controls group. 2. Select the Button command. 3. Your cursor will turn into a tiny crosshairs with a button icon . Place it in the spot where you want your command button to be, then click. 4. The Command Button Wizard will appear. In the Categories pane, select the category of button you want to add. We want to find a way to move more quickly to specific records, so we’ll choose the Record Navigation category. 5. The list in the Actions pane will update to reflect your chosen category. Select the action you want the button to perform, then click Next. For our example, we’ll choose Find Record.
Approved by Curriculum Development Centre 157 Oasis Radiant Computer Science, Book 10 6. You can now decide whether you want your button to include text or a picture. A live preview of your button appears on the left. To include text, select the Text option, then type the desired word or phrase into the text box. To include a picture, select the Picture option. You can decide to keep the default picture for that command button, or you can select another picture. Click Show All Pictures to choose from another command button icon or Browse... to choose a picture from your computer. 7. When you are satisfied with the appearance of your command button, click Next. 8. Type a name for the button. This name won’t appear on the button, but knowing the name will help you quickly identify
Oasis Radiant Computer Science, Book 10 158 Approved by Curriculum Development Centre the button if you ever want to modify it with the Property Sheet. After typing the button name, click Finish. 9. Switch to Form view to test the new button. Our Find Record button opens the Find and Replace dialogue box. Some users report that Access malfunctions while formatting forms. If you have a problem performing any of these tasks in Layout view, try switching to Design view. Modifying form layout When you create a form, Access arranges the form components in a default layout where the fields are neatly stacked on top of each other, all exactly the same width. While this layout is functional, you might find that it doesn’t fit your information in the best way. For instance, in the form below, most of the fields are almost completely empty because the data stored there doesn’t take up much room.
Approved by Curriculum Development Centre 159 Oasis Radiant Computer Science, Book 10 The form would fit the data a little better if we made the fields and command buttons smaller, and if we put some of them side by side. However, with the default layout you won’t be able to put two fields next to each other or resize one field or button without resizing all of them. This is because Access lines up form components in rows and columns. When you resize a field, you’re really resizing the column that contains it. To resize and rearrange our fields the way we want, we’ll have to modify the form layout. For instance, because the default layout for our form contains only two columns—one for the field labels and another for the fields—we would have to create a new column to put two fields side by side. We can do this using the command on the Arrange tab, which contains all of the tools you need to customise your form’s layout. If you’ve ever built and modified tables in Microsoft Word, you already know how to use most of these tools. Why use forms? Many of us fill out forms so often that we hardly even notice when we’re asked to use them. Forms are so popular because they’re useful for both the person asking for the information and the person providing it. They are a way of requiring information in a specific format, which means the person filling out the form knows exactly which information to include and where to put it. This is just as true of forms in Access. When you enter information into a form in Access, the data goes exactly where it’s supposed to go: into one or more related tables. While entering data into simple tables is fairly straightforward, data entry becomes more complicated as you start populating tables with records from elsewhere in the database. For instance, the Orders table in a bakery’s database might link to information about customers, products, and prices drawn from related tables. A record with information about a single order might look like this:
Oasis Radiant Computer Science, Book 10 160 Approved by Curriculum Development Centre In fact, in order to see the entire order you would also have to look at the Order Items table, where the menu items that make up each order are recorded. The records in these tables include ID numbers of records from other tables. You can’t learn much just by glancing at these records because the ID numbers don’t tell you much about the data they relate to. Plus, because you have to look at two tables just to view one order, you might have a challenging time even finding the right data. It’s easy to see how viewing or entering many records this way could become a difficult and tedious task. As you can see, this record is much easier to understand when viewed in a form. Modifying the record would be easier as well because you wouldn’t have to know any ID numbers to enter new data. When you’re using a form, you don’t have to worry about entering data into the right tables or in the right format; the form can handle those things itself. There’s no need to go back and forth between tables or to search carefully within a table for a certain record because forms let you see entire records one at a time. Not only do forms make the data entry process easier for users, but they also keep the database itself working smoothly. With forms, database designers can control exactly how users are able to interact with the database. They can even set restrictions on individual form components to ensure all of the needed data is entered and that it’s all entered in a valid format. This is useful because keeping data consistent and organised is essential for an accurate and powerful database. Working with forms To open an existing form: 1. Open your database, and locate the Navigation pane. 2. In the Navigation pane, locate the form you want to open. Forms are marked with the icon.
Approved by Curriculum Development Centre 161 Oasis Radiant Computer Science, Book 10 3. Double-click the name of the form. It will open and appear as a tab in the Document Tabs bar. Entering and modifying data Depending on the database you’re using, the forms you work with may include special tools and features that let you complete common tasks with one click of a button. You’ll see examples of these tools in the interactives on the next page. However, regardless of which type of form you’re working with you can follow the same procedures for carrying out certain basic tasks. To add a new record: There are two ways to add a new record to a form: • In the Records group on the Home tab of the Ribbon, click the New command. • On the Record Navigation bar at the bottom of the window, click the New Record button.
Oasis Radiant Computer Science, Book 10 162 Approved by Curriculum Development Centre To find an existing record to view or edit: There are two ways to find and view an existing record using a form, and they both use the navigation bar at the bottom of the screen: • To look through records one at a time, click the navigation arrows. The right arrow will take you to the next record, while the left arrow will take you to the previous one. • To search for a record, type a word you know is contained in that record in the navigation search box. To save the current record: 1. Select the Home tab, and locate the Records group. 2. Click the Save command. The current record will be saved. To delete the current record: 1. Select the Home tab, and locate the Records group. 2. Click the Delete command. The record will be permanently deleted. Sorting and Filtering Records Essentially, sorting and filtering are tools that let you organise your data. When you sort data, you are putting it in order. Filtering data lets you hide unimportant data and focus only on the data you’re interested in. Sorting records When you sort records, you are putting them into a logical order, with similar
Approved by Curriculum Development Centre 163 Oasis Radiant Computer Science, Book 10 data grouped together. As a result, sorted data is often simpler to read and understand than unsorted data. By default, Access sorts records by their ID numbers. However, there are many other ways records can be sorted. For example, the information in a database belonging to a bakery could be sorted in several ways: • Orders could be sorted by order date or by the last name of the customers who placed the orders. • Customers could be sorted by name or by the city or zip code where customers live. • Products could be sorted by name, category (pies, cakes, cupcakes, etc.), or price. You can sort both text and numbers in two ways: in ascending order and descending order. Ascending means going up, so an ascending sort will arrange numbers from smallest to largest and text from A to Z. Descending means going down, or largest to smallest for numbers and Z to A for text. The default ID number sort that appears in your tables is an ascending sort, which is why the lowest ID numbers appear first. In our example, we will be performing a sort on a table. However, you can sort records in any Access object. The procedure is largely the same. To sort records: 1. Select a field in the cell you want to sort by. In this example, we will sort by customers’ last names. 2. Click the Home tab on the Ribbon, and locate the Sort & Filter group. 3. Sort the field by selecting the Ascending or Descending command. o Select Ascending to sort text A to Z or to sort numbers from smallest to largest. We will select this in our example because we want the last names to be in A-to-Z order.
Oasis Radiant Computer Science, Book 10 164 Approved by Curriculum Development Centre o Select Descending to sort text Z to A or to sort numbers from largest to smallest. 4. The table will now be sorted by the selected field. 5. To save the new sort, click the Save command on the Quick Access toolbar. After you save the sort, the records will stay sorted that way until you perform another sort or remove the current one. To remove a sort, simply click the Remove Sort command. Filtering records Filters allow you to view only the data you want to see. When you create a filter, you set criteria for the data you want to display. The filter then searches all of the records in the table, finds the ones that meet your search criteria, and temporarily hides the ones that don’t. Filters are useful because they allow you to focus in on specific records without being distracted by the data you’re uninterested in. For instance, if you had a database that included customer and order information, you could create a filter to display only customers living within a certain city or only orders that contain a certain product. Viewing this data with a filter would be far more convenient than searching for it in a large table. In our examples and explanations, we will be applying filters to tables. However, you can apply filters to any Access object. The procedure is largely the same. To create a simple filter: 1. Click the drop-down arrow next to the field you want to filter by. We will filter by city because we want to see a list of customers who live in a certain city. 2. A drop-down menu with a checklist will appear. Only checked items will be included in the filtered results. Use the following options to determine which items will be included in your filter: Select and deselect items one at a time by clicking their check boxes. Here, we will deselect all of the options except for Cary.
Approved by Curriculum Development Centre 165 Oasis Radiant Computer Science, Book 10 Click Select All to include every item in the filter. Clicking Select All a second time will deselect all items. Click Blank to set the filter to find only the records with no data in the selected field. 3. Click OK. The filter will be applied. Our customers table now displays only customers who live in Cary. Creating a filter from a selection Filtering by selection allows you to select specific data from your table and find data that is similar or dissimilar to it. For instance, if you were working with a bakery’s database and wanted to search for all products whose names contained the word chocolate, you could select that word in one product name and create a filter with that selection. Creating a filter with a selection can be more convenient than setting up a simple filter if the field you’re working with contains many items. To create a filter from a selection: 1. Select the cell or data you want to create a filter with. We want to see a list of all products that contain the word chocolate in their names, so we’ll select the word chocolate in the Product Name field. 2. Select the Home tab on the Ribbon, and locate the Sort & Filter group.
Oasis Radiant Computer Science, Book 10 166 Approved by Curriculum Development Centre 3. Click the Selection drop-down arrow. 4. Select the type of filter you want to set up: Contains includes only records with cells that contain the selected data. We’ll select this because we want to see records that contain the word chocolate anywhere in the title. Does Not Contain includes all records except those with cells that contain the selected data. Ends With includes only records whose data for the selected field ends with the search term. Does Not End With includes all records except those whose data for the selected field ends with the search term. 5. The filter will be applied. Our table now displays only products with the word chocolate in their names. Working with queries Queries are a way of searching for and compiling data from one or more tables. Running a query is like asking a detailed question of your database. When you build a query in Access, you are defining specific search conditions to find exactly the data you want. How are queries used? Queries are far more powerful than the simple searches or filters you might use to find data within a table. This is because queries can draw their information from multiple tables. For example, while you could use a search in the customers table to find the name of one customer at your business or a filter on the orders table to view only orders placed within the past week, neither would let you view both customers and orders at once. However, you could easily run a query to find the name and phone number
Approved by Curriculum Development Centre 167 Oasis Radiant Computer Science, Book 10 of every customer who’s made a purchase within the past week. A well-designed query can give information you might not be able to find out simply by examining the data in your tables. When you run a query, the results are presented to you in a table, but when you design one you use a different view. This is called Query Design view, and it lets you see how your query is put together. Click the buttons in the interactive below to learn how to navigate the Query Design view. Queries and its types : Queries are database object that can be used to retrieve information from multiple tables by joining these tables using common fields. Simply, Queries are used to change, view, and analyse the data. In MS Access you can use queries to extract information (data) from one (or more) tables (or from other queries). For example you can write a query that returns all students that have a percentage that is less than 40. Besides limiting the number of records with queries, you can also limit the number of columns (fields). For example instead of returning all fields from the Student Table you can only select the Student ID, Student Name, Student percentage and Student Email address. There are different types of queries, they are:
Oasis Radiant Computer Science, Book 10 168 Approved by Curriculum Development Centre • Select Queries • Parameter Queries • Crosstab Queries • Action Queries. Select Queries: A select query asks a question about the data stored in tables and returns a result set in the form of a datasheet without changing the data. It retrieves data from one or more tables and displays the results in a datasheet where we can update records. A select query can contain specifications for the fields (columns) to return, the records (rows) to select, the order to put the records in, and the way to group (summarise) information. Select query can be used to: • View subset of records • Retrieve data from one (or more) tables • Display the results in a datasheet • Update the records from within the datasheet Parameter Queries: A parameter query is a query that displays a dialogue box prompting users for information, that information can be used for retrieving records or a value you want to insert in a field. You can design the query to prompt you for more than one piece of information; for example, you can design a query to prompt a user for two dates (beginning and end date). Access can then retrieve all records that fall between those two dates. Parameter queries can be used as the basis for forms, reports, and data access pages. For example, you can create a monthly earnings report based on a parameter query. When you print the report, Access displays a dialogue box asking for the month that you want the report to cover. You enter a month and Access prints the appropriate report. Crosstab Queries: Crosstab queries calculate a sum, average, count, or other type of total for data that is grouped by two types of information one down the left side of the datasheet and another across the top. Action Queries: An action query is a query that makes updates to many records at the same time. There are four types of action queries:
Approved by Curriculum Development Centre 169 Oasis Radiant Computer Science, Book 10 • Delete Queries: A delete query deletes a group of records from one or more tables. Delete queries remove the entire record, not just selected fields within records. • Update Queries: Using update query you can make global changes to a group of records in one or more tables. For example, you can increase marks by 10 percent for all Students (or a subset of students). • Append Queries: An append query adds a group of records from one or more tables to the end of one or more tables. For example, suppose that you drop students from one Class1 and register them for Class2. You can append records into the Class2 and delete them using a Delete query form Class1. • Make-Table Queries: A make-table query creates a new table from data in one or more tables. Designing a multi-table query Queries can be difficult to understand and build if you don’t have a good idea of what you’re trying to find and how to find it. A one-table query can be simple enough to make up as you go along, but to build anything more powerful you’ll need to plan the query in advance. Creating a multi-table query Now that we’ve planned our query, we’re ready to design and run it. If you have created written plans for your query, be sure to reference them often throughout the query design process. To create a multi-table query: 1. Select the Query Design Command from the Create tab on the Ribbon.
Oasis Radiant Computer Science, Book 10 170 Approved by Curriculum Development Centre 2. In the Show Table dialogue box that appears, select each table you want to include in your query, then click Add. After you’ve added all of the tables you want, click Close. When we planned our query, we decided we needed information from the Customers and Orders table, so we’ll add them. 3. The tables will appear in the Object Relationship pane, which is linked by a join line. Double-click the thin section of the join line between two tables to edit its join direction. 4. The Join Properties dialogue box will appear. Select an option to choose the direction of your join. o Choose option 2: for a left-to-right join. In our query, the left table is the Customers table, so choosing this would mean all of the customers who met our location criteria—whether or not they had placed an order— would be included in our results. We don’t want to choose this option for our query. o Choose option 3: for a right-to-left query. Because our right table is our Orders table, selecting this option will let us work with records for all of the orders and only the customers who’ve placed orders. We’ll choose this option for our query because this is exactly the data we want to see.
Approved by Curriculum Development Centre 171 Oasis Radiant Computer Science, Book 10 5. In the table windows, double-click the field names you want to include in your query. They will be added to the design grid in the bottom part of the screen. In our example, we’ll include most of the fields from the Customers table: First Name, Last Name, Address, City, State, Zip Code, and Phone Number. We’ll also include the ID number from the Orders table. 6. Set field criteria by entering the desired criteria in the criteria row of each field. We want to set two criteria: o First, to find customers who do not live in Raleigh, we’ll type Not In (“Raleigh”) in the City field. o Second, to find customers who have a phone number beginning with the area code 919, we’ll type Like (“919*”) in the Phone Number field. 7. After you have set your criteria, run the query by clicking the Run command on the Query Tools Design tab.
Oasis Radiant Computer Science, Book 10 172 Approved by Curriculum Development Centre 8. The query results will be displayed in the query’s Datasheet view, which looks like a table. If you want, save your query by clicking the Save command on the Quick Access toolbar. When prompted to name it, type the desired name, then click OK. Designing the Query • Click on Create • Choose Query Wizard We will get the dialogue box
Approved by Curriculum Development Centre 173 Oasis Radiant Computer Science, Book 10 • Choose Simple Query Wizard • Select the required fields to design the Query and choose Next • Choose Next. We will get another dialogue box. • Save the query and choose Finish • Now we have designed the query. Open the query in design view. Type the condition and Open it do the searching and filtering as our requirement.
Oasis Radiant Computer Science, Book 10 174 Approved by Curriculum Development Centre Designing Cross Tab Query • Click on Create Menu • Choose Query Wizard • Choose Crosstab Query Wizard and OK. We will get another dialogue box. • Now select the required tables or queries for designing Crosstab Query. We can pick up the multiple fields from different tables and queries for searching and filtering the data. In this example we have selected both table and queries and click on Next. • Select any two fields for making the row heading of the crosstab query and choose Next.
Approved by Curriculum Development Centre 175 Oasis Radiant Computer Science, Book 10 • Select any two fields for the column heading and choose Next. • Now select some functions like count, Max, Min, etc. as given in the following dialogue box. In this example we have selected the Count function for the address. • Now choose Next • Now save the crosstab Query and View it. • The above query report shows the list of records and counts the address for each address criteria. In the given table all the records has one address and no repeated address so it count 1 for all. Creating reports Reports give you the ability to present components of your database in an easyto-read, printable format. Access 2010 lets you create reports from both tables and queries.
Oasis Radiant Computer Science, Book 10 176 Approved by Curriculum Development Centre To create a report: 1. Open the table or query you want to use in your report. We want to print out a list of last month’s orders, so we’ll open up our Orders Query. 2. Select the Create tab on the Ribbon, and locate the Reports group. Click the Report command. 3. Access will create a new report based on your object. 4. It’s likely that some of your data will be located on the other side of the page break. To fix this, resize your fields. Simply select a field, then click and drag its edge until the field is the desired size. Repeat with additional fields until all of your fields fit. 5. To save your report, click the Save command on the Quick Access toolbar. When prompted, type a name for your report, then click OK. Just like tables and queries, reports can be sorted and filtered. Simply rightclick the field you want to sort or filter, then select the desired sorting or filtering option. Designing the report using report wizard. • Click on Create Menu • Choose Report Wizard
Approved by Curriculum Development Centre 177 Oasis Radiant Computer Science, Book 10 • We will get a dialogue box with the list of fields. • Select the fields and choose Next • Another dialogue box will display. Now see the table format and finish it to open the report. Printing and saving reports in Print Preview While you can print reports using commands in Backstage view, you can also use Print Preview. Print Preview shows you how your report will appear on the printed page. It also allows you to modify the way your report is displayed, print it, and even save it as a different file type. Click the buttons in the interactive below to learn about Print Preview.
Oasis Radiant Computer Science, Book 10 178 Approved by Curriculum Development Centre To print a report: 1. On the Home tab of the Ribbon, click the View command and select Print Preview from the drop-down list. Your report will be shown as it will appear on the printed page. 2. If necessary, modify the page size, margin width, and page orientation using the related commands on the Ribbon. 3. Click the Print command. 4. The Print dialogue box will appear. Set any desired print options, then click OK. Saving reports You can save reports in other formats so they will be viewable outside of Access.
Approved by Curriculum Development Centre 179 Oasis Radiant Computer Science, Book 10 This is called exporting a file, and it allows you to view and even modify reports in other formats and programs. Access offers options to save your report as an Excel file, text file, PDF, XPS file, email attachment, rich text file, or HTML document. Experiment with the different export options to find the one that best suits your needs. To export a report: 1. On the Home tab of the Ribbon, click the View command and select Print Preview from the drop-down list. 2. Locate the Data group on the Ribbon. 3. Select one of the file type options on the Ribbon, or click More to see options to save your report as a Word or HTML file. 4. Save your file. o If you’re saving the report as a PDF or XPS file: 1. Select the location where you want to save the report. 2. Place your cursor in the file name text box, and type a name for your report if you want to name it something other than the report title. 3. In the Save as Type dropdown menu, select either PDF or XPS. 4. Select the file quality by clicking either Standard for reports you plan on printing or Optimised for reports you plan on sharing primarily online. 5. Once you are satisfied with your settings, click Publish to save your report. o If you’re saving the report as any other type of file: 1. Click Browse to specify
Oasis Radiant Computer Science, Book 10 180 Approved by Curriculum Development Centre your file location and name, then click Save. 2. In the Export dialogue box, click the check boxes to select desired saving options where applicable. 3. Click OK to export your report. 5. A dialogue box will appear to notify you that your file has been successfully saved. Click Close to return to your report. Designing Your Own Database Now that you know how to use and modify existing databases, you might be interested in designing your own. Database design can be very complicated—so complicated, in fact, that people take extensive courses just to learn how to plan databases. Creating a database from a template Before deciding to build your own database, you may want to look at the templates included in Access to see if any of them match your needs. When you select a template, Access creates a new database based on that template. Once it’s created, you can fill the database with your own information or modify it to suit your needs. To create a database from a template: 1. Select the File tab. This will take you to Backstage view.
Approved by Curriculum Development Centre 181 Oasis Radiant Computer Science, Book 10 2. On the sidebar, click New. 3. Template options will appear. Under the Office.com Templates heading, you can see a list of templates grouped by type. Select the template type that best fits your needs. 4. Access will display all of the available templates of that type. Select a template to see more information on it, including a visual preview, on the right. 5. When you have found the template you want to use, click Download. The template will open automatically once it’s finished downloading.
Oasis Radiant Computer Science, Book 10 182 Approved by Curriculum Development Centre Points to remember • Database management system is the system that helps manage the database file. • Management of database file is the process to create a file, update file, copy file, generate reports and queries, etc. • MS Access is a powerful database management system developed by the Microsoft Company. • There are different objects inside MS Access. These are table, form, report, queries, etc. • Table defines the structure of database file. It defines the structure as numeric, text, date, etc. • Database file has so many advantages over the general file processing system. • DBMS has data sharing feature so that so many users can use single database file for different applications. • Wizard is the readymade format of table, forms or other objects of Access. • There is different field or data type which is the format of data on access. These are text, number, date and time, lookup wizard, OLE (Object linking and embedding) etc. • DBMS is useful for software development, billing, ticketing, library system, etc. There are eight types of queries. These are append query, delete query, select query, update query, SQL query, parameter query, action query, crosstab query. • We can create the relationship between two or more tables by the help of primary and foreign key. There are three types of relationship. These are one to one relation, one to many relation and many to many relationship. • Primary key is the key field where we cannot store repeated data on this field. So it can be defined as the field that accepts unique data.
Approved by Curriculum Development Centre 183 Oasis Radiant Computer Science, Book 10 Exercises 1. Answer the following questions. a. What is DBMS? b. Write the advantages and disadvantages of DBMS. c. Define MS Access. d. What is database file? e. What is RDBMS? f. List some data types used in MS Access. g. What is data type? h. What is data and information? i. What is wizard? j. What is redundant data? 2. Write the steps to perform the following: a. To create a database file. b. To create a table using wizard. c. To create a form using auto form columnar. d. To design report using auto report tabular. e. To view the design of table. f. To set primary key. g. To delete row/record. h. To insert field name. i. To make a query using simple design. j. To create form using wizard. 3. Differentiate between: a. Form and Table. b. Query and Report. c. Data and Information. d. DBMS and RDBMS. e. Text and Number Data type. 4. Fill in the blanks. a. There are some __________ in database. b. __________ are raw facts.
Oasis Radiant Computer Science, Book 10 184 Approved by Curriculum Development Centre c. Collection of data makes __________. d. Data type defines the __________ of data. e. Query helps for __________ records. 5. State True and False. a. RDBMS is relational database management system. b. Table is a data type name. c. Query helps to enter data. d. Primary key is a special field name that will not accept repeated data on that field. e. Wizard is readymade sample of design. 6. Class Activities and Project Work. a. Make a list of fields and their data type for address collection of your class. b. Prepare a list of field and data type for: i) Result processing ii) Preparation of bill iii) Library system c. Prepare: i) Table ii) Form iii) Report iv) Query By using above list of fields using wizards or design view.
Approved by Curriculum Development Centre 185 Oasis Radiant Computer Science, Book 10 Chapter 8 Review of QBASIC Programming ffl Data types in QBASIC ffl System commands of QBASIC ffl Types of statements ffl Functions in QBASIC THIS CHAPTER COVERS :
Oasis Radiant Computer Science, Book 10 186 Approved by Curriculum Development Centre Data type is an indicator that tells us what kind of value must be stored in a variable, like if we want to store number in a variable, its data type has to be numeric. Every variable used in the programme has a data type. There are five types of variables. Each one has its own associated suffix to identify its type. 1. String (s$) - This variable stores alphabets or alphanumeric values and is indicated by a $ (dollar) sign after the variable name as a suffix. It can also store numbers but they cannot be used for doing mathematical calculations. String length: Minimum value= 0 characters Maximum value = 32767 characters 2. Integer (N%) - This variable stores number with no fractional part i.e no decimal number. It is indicated by a % (percent) sign after the variable name as a suffix. It occupies 2 bytes of space in the memory. Integer length: Minimum value = -32768 numbers maximum value = 32767 numbers 3. Long Integer (N&) - This variable also stores an integer value i.e. nondecimal number. It is indicated by an ampersand sign, &, after the variable name as suffix. It occupies 4 bytes of space in the memory. Long integer length: minimum value =-2,147,483,648 numbers Maximum value = 2,147,483,647 numbers 4. Single Precision Number (N!) - This variable can store single-precision values i.e. decimal or non-decimal numbers upto 7 digits. It is indicated by an exclamation sign, !, after the variable name as suffix. It occupies 4 bytes of space in the memory. Single precision length : Minimum value =-3.37*10^(38) Maximum value = 3.37*10^(38) 5. Double Precision Number (N#) - This variable can store double-precision values i.e decimal as well as non-decimal values upto 15 digits and occupies 8 bytes of space in the memory. It is indicated by a hash sign, #, after the variable name as suffix. Double precision length: Minimum value Data Types in QBASIC 8 Chapter
Approved by Curriculum Development Centre 187 Oasis Radiant Computer Science, Book 10 =-1.67*10^(308) Maximum value = 1.67* 10^(308) Variable and Constant Variable: A location or a address for storing values are variables. Variable name can be upto 40 characters long. There are two types of variable, numeric and string. A variable that stores numbers are numeric variable. For example. A, Num, xyz are numeric variables. A variable that stores alphanumeric values are string variables. It is indicated by $ sign, e.g., A$, Num$, xyz$. Constant: A fixed value of variable that remains the same during the execution of programme is a constant. The values of variables like 10,20,3.14, “Ram”, “Pokhara” and son on are constant. System commands of Qbasic Files: This command displays the list of files and directories (folders). Syntax: Files E.g. :- Files (displays list of files and directories of default drive.) Files “D:\*.bas” (displays list of all the files having extension .bas of D:drive.) CHDIR :-This command changes the default directory with specified directory. Syntax :- CHDIR e.g:- CHDIR c:\ABC” (Changes the default directory with ABC directory in C:drive.) MKDIR: This command creates a new directory to the specified location. Syntax: MKDIR E.g. :- MKDIR”D:\Book” (creates a new folder named Book in D:drive.) RMDIR: This command removes as empty directory from the specified location. Syntax:- RMDIR E.g.:- RMDIR” D:\Book” (deletes the directory named book from D:drive.) Name ……As: This command renames a file with a new name. Syntax: NAME< “old file name”> AS< “ new file name”> E.g.:- NAME” temp. dat” AS” record. dat” (renames a file named temp.dat with record.dat.) Kill: This command deletes a file or group of files from the specified location. Syntax:- KILL E.g. :- KILL “record.dat” (deletes a file named record.dat.) SHELL: This command changes Qbasic environment to DoS Syntax :-System E.g.;- SHELL(changes Qbasic mode to DOS mode.)
Oasis Radiant Computer Science, Book 10 188 Approved by Curriculum Development Centre SYSTEM: This command exits from Qbasic environment permanently. It closes the Qbasic programme. Syntax: SYSTEM E.g. :- SYSTEM (exits from the Qbasic Programme.) Statement: The statement is a collection of commands used in the programme. CLS, INPUT, PRINT, REM, END etc. are examples of QBASIC statements. Statements can be categorised into four groups: a. Declaration statement b. Assignment statement c. Input/Output statement d. Control flow statement a. Declaration statements: The statements which are used to declare variables in the programme are called declaration statements. DIM, CONST, REM etc. are examples of declaration statements. DIM statements: DIM statement is specially used to declare array variables. Though it can be also used to declare simple variable. Syntax : DIM Variables AS data type ------------> simple variable declaration DIM variables (subscript) -------------> Array variable declaration Example: DIM NAME AS STRING DIM AGE AS INTEGER ------------ > Simple variable declaration DIM NAMES$ (5) DIM AGE (5) ----------> Array variable declaration CONST statement: Here CONST stands for constant. According to its name this statement is used to store constant value in particular variable throughout the programme execution. Syntax: CONST Example: CONST PI = 22/7 REM Statement : REM Statement is used to give remarks to the programme. It is a nonexecutable statement which can also be denoted by single quotation (‘).
Approved by Curriculum Development Centre 189 Oasis Radiant Computer Science, Book 10 Syntax: REM Example: REM Program to calculate the area of a triangle or programme to find the perimeter of a rectangle. b. Assignment statements: The statements which are used to assign a numeric or string value to a variable are called assignment statements. LET, SWAP, READ …. DATA etc. are the examples of assignment statements. LET statement It is used to assign a numeric value or a string expression to a variable. But it is an optional statement. Syntax : LET <variable>= <string expression/value> Example : LET a=25 LET C$ =”COMPUTER” SWAP statement This statement is used to exchange the values of two similar type of variables. Syntax : SWAP <variable1,variable2> Example: CLS A=5 B=10 C=15 D=20 PRINT “Before swapping” PRINT A,B,C,D SWAP A,B SWAP C,D PRINT “After swapping” PRINT A,B,C,D
Oasis Radiant Computer Science, Book 10 190 Approved by Curriculum Development Centre END OUTPUT Before Swapping 5 10 15 20 After Swapping 10 5 20 15 READ …… DATA Statement Read ....... Data is used as complimentary to each other. READ statement reads multiple values by multiple variables from the data listed in the DATA statement. The number of data listed in DATA statement must be equal or more than the variables in READ statement. Syntax READ Variable1, variable2, ………. DATA value1, value2, ………….. Example : CLS READ SNO, NAM$, CL PRINT SNO, NAM$, CL DATA 5, RAM, 9 END OUTPUT 5 Ram 9 c. Input/output statements: Input/output statements are statements that allow the user to input data to the computer and print the data. They are used to perform input/output operations for the computer. INPUT, PRINT, LPRINT, etc. are some examples of input/output statements. CLS statement: It clears the previous output from the display screen and makes the screen blank.
Approved by Curriculum Development Centre 191 Oasis Radiant Computer Science, Book 10 syntax: CLS Example: CLS INPUT statement INPUT statement is used to read input from the keyboard during programme execution. Syntax INPUT<”PROMPT”><;/,><var1,var2,var3,……..> Example : INPUT “Enter your name “;n$ INPUT “Enter your roll no.and section”;r,sec$ LINE INPUT statement This statement allows to input line of data at a time and assign into single variable. It can accept complete line of maximum 255 characters. syntax : LINE INPUT “string”;string variable Example : CLS LINE INPUT “please enter the line of text “;n$ PRINT N$ END OUTPUT Please enter the line of text ? Computer Science Computer Science INPUT$ FUNCTION returns a string of characters read from specified files. syntax : INPUT$ (n[,[#]filenumber%]) where, n is the number of characters (bytes ) to read. File number % is the number of an open file. If file number % is omitted, INPUT$ reads from the keyboard. Example : OPEN “TEST. DAT” FOR OUTPUT AS #1 PRINT #1, “COMPUTER” CLOSE#1 OPEN “TEST. DAT’ FOR INPUT AS#1 PRINT INPUT$ (3,1) ‘Print first 3 characters. CLOSE #1
Oasis Radiant Computer Science, Book 10 192 Approved by Curriculum Development Centre OUTPUT COM INKEY$ Function Reads a character from the keyboard. Syntax : INKEY$ (ASCLL.CODE) Example: PRINT “press Esc to exit …” DO PRINT “Computer Science” LOOP UNTIL INKEYS$ (27)’27 is the ASCCI code for Esc. PRINT (?) statement Print statement is used to display the output of the programme to display whatever is written between double quotation marks. Syntax :- PRINT [LIST OF EXPRESSION] PRINT “ I’m a students of class 6” ? “Computer” LPRINT statement This statement works just like a print statement, the only difference is that, it sends the output to the printer and not to the screen. Syntax : LPRINT <;/,> Example : CLS LPRINT “Computer Science” PRINT USING statement PRINT USING writes formatted output to the screen or to a file. syntax : PRINT USING “formatting string”; expression ! displays only the first character of string & Displays all the string # Digit position is specified ** Prints asterisk in the leading spaces. The two asterisks also specify two digits position.
Approved by Curriculum Development Centre 193 Oasis Radiant Computer Science, Book 10 $$ Prints a dollar sign in front of the numeric value Example 1 : X$ = “###.###” A = 100 : B=50.50: C=150.5 PRINT USING X$;A PRINT USING X$;B PRINT USING X$;C END OUTPUT 100 . 000 50. 500 150.500 Example 2: CLS PRINT USING”!” ;”Computer ”; “Science”; “Ten.” PRINT USING “&”; “Computer Science Ten.” PRINT USING “$####.”;34 PRINT USING “**####.”.34 OUTPUT CST Computer Science Ten. $34. ****34. TAB Function It inserts given number of spaces before printing. It is used with PRINT or LPRINT statements. Syntax: TAB (column%) Example :
Oasis Radiant Computer Science, Book 10 194 Approved by Curriculum Development Centre PRINT “KATHMANDU”; TAB (25); “NEPAL” A$ = “MOUSE” B$= “COMPUTER” PRINT A$;TAB (10); B$ OUTPUT: KATHMANDU NEPAL OUTPUT: MOUSE COMPUTER LOCATE Function LOCATE moves the cursor to a specified position on the screen. Syntax : LOCATE [row%], [column%] Example : CLS LOCATE 5,5 PRINT “Computer Science “ OUTPUT: Computer Science d. Control statements: The statements which are used to control the flow of execution of the programme statements(s) are called control flow statements. The control flow statements are used to make decision or to control programme flow at the time of programme execution. This statement is also known as branching and jumping statements. Branching and jumping refers to departure of programme execution from one line to another line of the same programme conditionally or unconditionally. GOTO, IF…Then, SELECT CASE etc. are the examples of control flow statements. These statements are classified into two types: i. Conditional statement ii. Unconditional statement Conditional statement transfers the flow of programme execution according to the condition. IF….THEN, SELECT CASE etc. are used for conditional statements. On the other hand unconditional statements transfer the
Approved by Curriculum Development Centre 195 Oasis Radiant Computer Science, Book 10 flow of programme execution without any condition. GOTO statement is used for this purpose. GOTO statement The GOTO statement is the unconditional branching (jumping) statement. It branches the control flow to the given line without testing a condition. Syntax : GOTO [line number/label] Example : CLS A=1 PRINT A GOTO LABEL B=7 PRINT B LABEL : END OUTPUT: 1 The output of the above programme is 1 because after displaying the value of A the GOTO statement forces a jump to the line LABEL and programme terminates. IF statements We know that QBASIC executes the instructions of programme sequentially one after another. But sometimes problems cannot be solved sequentially. So, we need to branch or jump from one line to another line. IF….THEN statement is the conditional branching (jumping) statement. This statement is used to make decision. It executes block of statement depending upon the given condition. The condition is given between IF and THEN. If the condition is true it performs task and if the condition is false the execution continues with the next executable statement. It branches the control flow according the given condition. This statement can be used in different ways:
Oasis Radiant Computer Science, Book 10 196 Approved by Curriculum Development Centre i) IF ….. THEN statement Syntax : IF THEN Example : CLS INPUT “Enter first number”; A INPUT “Enter second number”; B IF A > B THEN PRINT A END OUTPUT: Enter first number ? 10 Enter second number ? 5 10 Example: REM Program to enter any three numbers and print the middle number. CLS INPUT “Enter first number”; A INPUT “Enter second number”; B INPUT “enter third number”; C IF (A >B AND AC) THEN M=A IF (B>A AND BC) THEN M=B IF (C>A AND CB) THEN M=C PRINT “The middle number is “; M END REM program to find Even or Odd. CLS INPUT “Enter a number”; N R = N MOD 2 IF R = 0 THEN PRINT “Even”
Approved by Curriculum Development Centre 197 Oasis Radiant Computer Science, Book 10 ELSE PRINT “Odd” END Example : REM to find smallest among three numbers. CLS INPUT “Enter three Numbers”; A, B, C IF A<B AND A<C THEN S=A IF B<A AND B<C THEN S=B IF C<A AND C<B THEN S=C PRINT “Smallest number is”; S END ii) IF … THEN … ELSE statement Syntax : IF <condition>THEN <statement1> ELSE END IF Example : CLS INPUT “Enter any number”; N I F N MOD 2 = O THEN PRINT “EVEN NUMBER” ELSE PRINT “ODD NUMBER” END IF END OUTPUT:
Oasis Radiant Computer Science, Book 10 198 Approved by Curriculum Development Centre Enter any number ? 5 Odd Number iii) IF …THEN…ELSE IF statement Syntax : IF <condition> THEN <statement1> ELSE IF <condition> THEN <statement2> ………………… ………………… ELSE <statement> END IF END Example : CLS INPUT “enter a number”; N IF N<100 THEN PRINT “It is lesser than 100” ELSEIF N=100 THEN PRINT “It is equal to 100” ELSE PRINT “It is greater than 100” END IF END Example : REM Program that will read your percentage and display your position/rank. CLS INPUT “enter your percentage “;p
Approved by Curriculum Development Centre 199 Oasis Radiant Computer Science, Book 10 IF N =80 THEN PRINT “you passed with distinction” ELSE IF P >= 60 THEN PRINT “you passed with first division” ELSE IF P > 45 THEN PRINT “you are passed in second division” ELSE IF P >= 32 THEN PRINT “you passed with third division” ELSE PRINT “you failed” END IF END SELECT CASE statement Executes one of several statement blocks depending on the value of an expression. Syntax : SELECT CASE test expression1 CASE expressionlist1 [ statement block1] CASE expressionlist2 [statementblock2] CASE CLSE [statementblock-n] Example : INPUT “Enter Your Percentage”; Per SELECT CASE PER CASE IS >=90 PRINT “YOU GOT A+” CASE 80 TO 89 PRINT “YOU GOT A”
Oasis Radiant Computer Science, Book 10 200 Approved by Curriculum Development Centre CASE 70 TO 79 PRINT “YOU GOT B+” CASE 60 TO 69 PRINT “YOU GOT B” CASE 50 TO 59 PRINT “YOUT GOT C+” CASE 40 TO 49 PRINT “YOU GOT C” CASE ELSE PRINT “Sorry, Very Low Grade” END SELECT OUTPUT: Enter your percentage ? 95 You Got A+ Looping in QBASIC The term looping means repeating execution of a sequence of statements in a programme. The loop is repeated as long as the given condition is satisfied. It is terminated when given condition is not satisfied. A loop becomes endless if it is not terminated. In QBASIC there are several statements for creating a loop like : 1. FOR … NEXT 2. WHILE … WEND 3. DO … LOOP FOR … NEXT LOOP It repeats a statement or a block of statements for given number of times which is written in between FOR and NEXT. Syntax : FOR <counter>= <initial value>TO <sentinel value> <step+/->