27
Lab 7 – Access Data Entry and Queries MBAC 611

MBAC 611. Click on the My Computer Icon Open your private network directory Create a new folder named lab7 Copy your lab6 Access file to the lab7

Embed Size (px)

Citation preview

Lab 6 Access Data Entry and Queries

Lab 7 Access Data Entry and QueriesMBAC 611Lab 7 PreparationClick on the My Computer Icon

Open your private network directory

Create a new folder named lab7

Copy your lab6 Access file to the lab7 folder

Rename the copied lab6 Access file to lab7

Double Click on the lab7 Access file

If you see the following warning you can select

This warning is prompted by the fact that programs can be created and run from within Access.

So when you dont know where a database originated from it is a good idea to let Access block these programs (what is called active content). You should now be in Access.Access TablesYou should see the three Access table names on the left hand side of the screen.

These are the three tables you created during your last lab.

Table Data EntryDouble-click on the tab.

This allows data to be entered in the fields.

Cust_IDFirst_NameLast_NameStreet_AddressCityStateZip1HowardSmith123 Main St.TrentonNJ112322DavidMay456 12th AveAlbanyNY104573JaneLynn789 8th St.IrvineCA763214SteveBerliner532 Maple Dr.AustinTX87431We are going to enter the following data into the Customer table.

Unfortunately, you cannot copy/paste whole records in Access.

However, you copy/paste an individual field value this may be useful for the Street_Address field.Enter the above data into the Customer table. Once entered, we need to save the data.

Right-click on the tab and then select .

Right-click on the tab and then select .

Purchase TableWe will now enter data into the Purchase Table.

Double-click on the table tab.

You should see the following empty table.

Cust_IDItem_IDPurchase_DateNum_Bought27211/5/03334563/9/05119014/7/07234358/4/031Enter the following data into the Purchase Table.

You will need to enter one row at a time as the key consists of the first three fields. Key fields cannot be blank.

In Access the TAB or ENTER key can be used to move to the next field.Save and Close the table when done.Item TableWe will now enter data into the Item Table.

Double-click on the table tab.

You should see the following empty table.

Item_IDItem_NamePriceNum_Left456Pen1.254901Pencil1.008721GI Joe15.991435Barbie23.994Enter the following data into the Item Table.Save and Close the table when done.Notice that Access automatically places the dollar sign next to entries in the Price field.

This is due to the fact that we declared the Price field to be of type Currency.QueriesAccess allows us to query the data using a graphical method called Query By Example (QBE)

It also allows us to Query using SQL

QBE entries are converted to SQL and then executed to return the answer.Query 1We will now create the query to list the first and last name of all customers who live in the state of NJ.

The Customer table has the information we need.

We need to query the state field.Creating A QueryClick on the tab.

Click the icon. The following screen should appear:

From the Show Table dialog box select Customer and click

Then select

We want to display the first and last name so lets add those fields to the query detail area near the bottom of the screen.

Select and from the first and second column. We will also need the field so select that as well.

Query CriteriaWe are looking for individuals who live in New Jersey so lets place the value NJ into the Criteria section of the State field.

Since NJ is a text value we need to place it in double quotes. If you forget to do so Access will add them for you when you move off the field.

Running The QueryTo run the query click the icon located near the upper left hand corner of the Excel screen.

Our answer should appear in a New Table. The table is called Query 1.

Modifying the QueryOnce we have our answer we can still modify our query and then re-run it.

Right-click on the tab and select

Lets modify the query so that it doesnt display the state field we know it will be NJ.

Click the check box in the State field.

Your query detail area should look like the following. Run the query by clicking on the icon.

Notice that the State field is no longer displayed.

Viewing The SQL Code

Right-click on the tab.

Select the selection.

SQL CodeSELECT Customer.First_Name, Customer.Last_NameFROM CustomerWHERE (((Customer.State)="NJ"));

The extra parenthesis are not necessary. They have probably been placed to accommodate future criteria or queries involving field names that include spaces.Remove the extra parenthesis in the SQL code and re-run the query to verify that it works.

The code should appear as follows:

SELECT Customer.First_Name, Customer.Last_NameFROM CustomerWHERE Customer.State="NJ";

Saving The Query

Right-click on the tab.Select the selection.

Change the Query 1 value in the Query Name Dialog Box to Question 1.

Notice the Query appears under the Queries listing:

Query AssignmentCreate a query that does the following:

List the Item_ID and Price of the item named Barbie.

Hint: This requires the Item table.

The answer should be:

Save the query under the name Question 2.

Quit Microsoft Access.

You wont be able to submit the file if the database is open. A lock is placed on the file until you quit Access.

Submit the Lab7 Access file to the Lab7 Moodle Assignment. Submitting The Lab