Creating A Lookup With Microsoft Access Tables

17,068 views

Published on

In this tutorial we will lookup values in one table based on values in another. You may be familiar with the lookup concept if in Excel you have used VLookup or HLookup functions. I am going to use a really simple example to get you started.

Published in: Technology
1 Comment
1 Like
Statistics
Notes
No Downloads
Views
Total views
17,068
On SlideShare
0
From Embeds
0
Number of Embeds
62
Actions
Shares
0
Downloads
93
Comments
1
Likes
1
Embeds 0
No embeds

No notes for slide

Creating A Lookup With Microsoft Access Tables

  1. 1. Creating a Lookup with Microsoft Access Tables Microsoft Office Training Access Training
  2. 2. The task at hand… <ul><li>In this example we will lookup values in one table based on values in another. You may be familiar with the lookup concept if in Excel you have used VLookup or HLookup functions. I am going to use a really simple example to get you started. </li></ul>
  3. 3. The Products Table <ul><li>Create a new table and save it as tblProducts. Create the following fields in this table: </li></ul><ul><li>Field Name Data Type </li></ul><ul><li>ProductID AutoNumber </li></ul><ul><li>ProductName Text </li></ul><ul><li>ProductPrice Currency </li></ul><ul><li>Set ProductID as the primary key </li></ul>
  4. 4. The Products Table <ul><li>Enter the following data into the tblProducts Table </li></ul><ul><li>Product ID Product Name ProductPrice </li></ul><ul><li>1 A £5.99 </li></ul><ul><li>2 B £10.59 </li></ul><ul><li>3 C £21.99 </li></ul><ul><li>4 D £35.49 </li></ul><ul><li>5 E £19.99 </li></ul><ul><li>That’s you first table done, you can now close it. </li></ul>
  5. 5. The Discounts Table <ul><li>The second table will contain information about discounts. The discount amount is dependant on the price of the product. For example if the product cost under £10 you only get a £2 discount. If it’s between £10 and £19.99 you get a whopping £5 discount – too good to be true you might say! There are other discount available too. </li></ul>
  6. 6. The Discounts Table <ul><li>Create a new table and save it as tblDiscounts. Create the following fields in this table: </li></ul><ul><li>Field Name Data Type </li></ul><ul><li>DiscountID AutoNumber </li></ul><ul><li>StartPrice Currency </li></ul><ul><li>EndPrice Currency </li></ul><ul><li>Discount Currency </li></ul><ul><li>Set DiscountID as the primary key </li></ul>
  7. 7. The Discounts Table <ul><li>Enter the following data into the tblDiscounts table: </li></ul><ul><li>QuantityID StartPrice EndPrice Discount </li></ul><ul><li>1 £0.00 £9.99 £2 </li></ul><ul><li>2 £10.00 £19.99 £5 </li></ul><ul><li>3 £20.00 £29.99 £8 </li></ul><ul><li>4 £30.00 £39.99 £10 </li></ul><ul><li>5 £40.00 £49.99 £12 </li></ul><ul><li>Now close the table </li></ul>
  8. 8. Create a Lookup Query <ul><li>Nearly there now, all we have to do is create a query that includes both tables. Create a new query in design view adding both the tblProducts table and the tblDiscounts table to the query. </li></ul>
  9. 9. Create a Lookup Query <ul><li>Now add the following fields to the query grid: </li></ul><ul><li>From the tblProducts table add: ProductName & ProductPrice </li></ul><ul><li>From the tblDiscounts table add: Discount </li></ul><ul><li>In the criteria row for the ProductPrice field type the following: </li></ul><ul><li>Between [tblDiscounts].[StartPrice] And [tblDiscounts].[EndPrice] </li></ul>
  10. 10. Create a Lookup Query <ul><li>Save the query as qryDiscountLookup. Now run the query to see the appropriate discount displayed for each product. </li></ul>
  11. 11. Create a Lookup Query <ul><li>You could calculate the new sale price if you liked. To do this switch back to design view in your query and in the next available field in your query grid write the following in the Field: row. </li></ul><ul><li>SalePrice: [ProductPrice]-[Discount] </li></ul><ul><li>Before you run the query you had better format your new calculated field to show the result in currency format. To do this click into the field on the query grid then click View | Properties. In the Field properties window find the Format properties and choose Currency . </li></ul>
  12. 12. Create a Lookup Query <ul><li>Save and run query again. You should have the discounted price for each product displayed in your new SalePrice field. </li></ul>
  13. 13. More Access Tutorials <ul><li>For more Access Tutorials visit the Blue Pecan Free Microsoft Office Training page. </li></ul><ul><li>For a direct link to this Access tutorial </li></ul>

×