Start learning with our library of video tutorials taught by experts. Get started
Viewers: in countries Watching now:
In this course, author Adam Wilbert illustrates how to create and leverage real-world queries and turn raw data into usable information. The course covers setting up queries, performing calculations, using the built-in Access functions to further refine query results, and identifying top performers or areas for improvement based on a range of criteria.
Creating an archive database is a great way to house older data that you might want to reference occasionally, but don't necessarily need in your day-to-day working database. Such as old financial records or sales records. We can accomplish this by using three action queries. The Make Table, Append, and Delete queries. By now, I'm sure you know the drill. Make sure your backup is in place before applying any of the action queries. So let's take a look at how we can create an archive database of some of our older orders. I'll go to the Create tab and Ill create a new query in Design view.
I'm interested in making an archive database of our older orders so I'll choose my Orders table and close the Show Table window. Now I want to export all of our old order records to this external database and a shortcut to add everything from one table to our query is to double-click on this asterisk character at the top. The next thing I want to do is export only the orders that are older than two years old. We'll add an OrderDate field so we can supply that criteria. In the Criteria box, I'll right- click and say Zoom so I can type it in.
So I'm looking for all of the orders that are more than two years old. In other words, I want to identify a date two years ago from today and find the orders that are older than that. We can do that with the DateAdd function that we saw earlier in the course. First I'll type a less than or equals to and then my DateAdd function. The first part of our DateAdd is what units we want to add or subtract. We're going to subtract two years, so I'll type in "yyyy" to denote the unit years.
The second piece is how many units. We'll go in two years in the past, so we want -2. Finally, the third component is what day we want to add or subtract from. We want to subtract two years from today, so I'll supply the Date function. This will denote today's date. I'll use a closing parenthesis to finish my function and now I've got a function that will choose all the orders that are older than two years old. We'll go ahead and say OK and run the query to preview the results.
You can see I have a total of 1756 records that are more than two years old. Let's archive these and get them out of our working database. I'll switch back into Design view, and before I do this I want to make sure that I turn off the Show checkbox under OrderDate. We're only using this field to choose the criteria to find the orders that are more than two years old. All the records that are going to be exported are represented by this asterisk in the tbl_Orders. So everything in the tbl_Orders is going to be exported and then we're only using the OrderDate field to select the criteria.
Let's go ahead and use a Make Table action query to make a copy of the records and put them in the archive database. Then we'll follow that up with a Delete query to remove the same records from the current database. Let's go ahead and change this to a Make Table query by clicking the Make Table button in the Query Type and Access asks us do we want to create a table in the current database or in another database. I'll choose Another and we'll find the archive database in our exercise 8 folder.
Chapter 8/TwoTreesArchive. Go ahead and say OK and now we need to supply a name for this new table. I'm going to call it ArchiveOrders. We'll say OK and we'll run the query. Access tells us that we're about to paste 1756 rows into the new table. Once you click Yes, you can't Undo the command. Go ahead and say Yes and Access will have copied all of those records into the archive database. But unfortunately, it doesn't give us any sort of message to tell us that it happens.
It just does as soon as you click OK. Now that our records are archived, we want to delete the exact same records from the current database. We could follow this up by switching to a Delete query and we'll see this new line here that says Delete. Let's go ahead and say Run, and Access tells us we're about to delete 1756 rows from the specified table. We'll go ahead and say Yes and the action is done. If we try and run it again, we should get 0 because those records have already been deleted.
Go ahead and say No to this. Let's take a look at our archive database to see what things look like over there. I'll go to my File tab, Open, and I'll select my archive database from the Chapter 8 folder. I'll open that up. Access is going to ask me if I want to save the existing query that we're working on, and we can just say No. I'm going to go ahead and click on the security warning to hide the message bar, and we'll take a look at our ArchiveOrders table that we created with the action query. We'll see 1756 records.
These are the records that we just exported from the other table. Once the ArchiveOrders table has been created in the archive database, any further archivings that come out of your working database would use an Append query instead of Make Table. The Make Table is to make a brand new table. Append does the same functionality. It just adds records to the bottom. Once you're confident that your data has been archived successfully, it's a simple matter to convert your Make Table or Append query into a Delete query to remove the records from your current database that you just archived.
Because the structure of the query is the same, only the type of the query is changed, changing from one type directly to the other ensures that the records that you delete are exactly the same records that you just copied.
There are currently no FAQs about Access 2010: Queries in Depth.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.