* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download Tutorial 8 - Fredonia.edu
Survey
Document related concepts
Data center wikipedia , lookup
Concurrency control wikipedia , lookup
Data analysis wikipedia , lookup
Information privacy law wikipedia , lookup
Microsoft Access wikipedia , lookup
3D optical data storage wikipedia , lookup
Entity–attribute–value model wikipedia , lookup
Business intelligence wikipedia , lookup
Open data in the United Kingdom wikipedia , lookup
Data vault modeling wikipedia , lookup
Microsoft SQL Server wikipedia , lookup
Microsoft Jet Database Engine wikipedia , lookup
Versant Object Database wikipedia , lookup
Clusterpoint wikipedia , lookup
Transcript
Tutorial 8 Excel The Select Statement and the MsgBox Function Microsoft Query The Excel lesson makes use of an Access database called MthSales.mdb and an Excel worksheet T8-EX-1.xls Data from the Access database is brought into the Excel worksheet by using a program called Microsoft Query. Query can be used to bring in the initial data and also used to update the worksheet data whenever the Access database is updated. How to instruct the Excel worksheet to make use of Query Click the top left cell where the data will reside, click Data on the menu bar, point to Get External Data, and then New Database Query, then MS Access Database*. You will then be able to Browse and select the MthSales.mdb. You will be asked to select which fields of the database you want to include in the transfer. Selecting the name of the Table, 2002Sales will select all fields. To mark them for transfer you will then click on the ">" key, which will place them in the Columns in you query window. Click on the Next button. You are now asked to provide a Filter. This would select only designated records from the database. We will not be using this feature, so select Next button. The Sort window allows you to optionally sort the data as it is being brought into the worksheet. We will be writing a macro to sort the data later, so select Next to skip this feature. The Returning External Data to Microsoft Excel window will indicate where the data is to be stored. You can reset this value by selecting a different cell. Name the query "SalesQuery" by clicking the Properties button from the Returning External Data window. Select: Query from MS Access Database and provide a name for the query. Make sure all checkboxes are checked as they are on page 470. Click the Finish button. Click OK to leave the External Data window, then OK again to leave the Retuning External Data window. Query Table Objects The range of cells retuned from the database is called a Query Table. A variable may be declared as a QueryTable as follows: Dim qtbSales as QueryTable Query Table objects are part of the Query Tables collection in Excel. The proper format for accessing the Query Table objects is to Set an object variable name to the worksheet, such as shtSales. Then Set the address of the query table: Set qtbSales = shtSales.QueryTables("SalesQuery") Structured Query Language (SQL) Select statements SQL statements are used to extract records from databases. Since we are extracting data from a database (into Excel) we will be able to select records based upon specific criteria using the SQL Select statement. Several SQL Select statements are shown on page 473. Date Variable in SQL Query qtbSales.CommandText = _ "Select * From 2002Sales where Month = #" & dtmDue & "#" Note the use of 2002Sales. This is the name of the Table from the database where the data is to be extracted from. Only those records that match the condition that the Month field matches the dtmDue date variable will be selected.