You are previewing Access Data Analysis Cookbook.
O'Reilly logo
Access Data Analysis Cookbook

Book Description

If you have large quantities of data in a Microsoft Access database, and need to study that data in depth, this book is a data cruncher's dream. Access Data Analysis Cookbook offers practical recipes to solve a variety of common problems that users have with extracting Access data and performing calculations on it. Each recipe includes a discussion on how and why the solution works. Whether you use Access 2007 or an earlier version, this book will teach you new methods to query data, different ways to move data in and out of Access, how to calculate answers to financial and investment issues, and more. Learn how to apply statistics to summarize business information, how to jump beyond SQL by manipulating data with VBA, how to process dates and times, and even how to reach into the Excel data analysis toolkit. Recipes demonstrate ways to:

  • Develop basic and sophisticated queries

  • Apply aggregate functions, custom functions, regular expressions, and crosstabs

  • Apply queries to perform non-passive activities such as inserting, updating, and deleting data

  • Create and manipulate tables and queries programmatically

  • Manage text-based data, including methods to isolate parts of a string and ways to work with numbers that are stored as text

  • Use arrays, read and write to the Windows registry, encrypt data, and use transaction processing

  • Use the FileSystemObject, use XML with XSLT, communicate with SQL Server, and exchange data with other Office products

  • Find answers from time-based data, such as how to add time, count elapsed time, work with leap years, and how to manage time zones in your calculations

  • Deal with business and finance problems, including methods for calculating depreciation, loan paybacks, and Return on Investment (ROI)

  • Explore statistical techniques, such as frequency, variance, kurtosis, linear regression, combinations and permutations

Access Data Analysis Cookbook is a one-stop-shop for extracting nuggets of valuable information from your database, and anyone with Access experience will benefit from these tips and techniques, including seasoned developers. If you want to use your data, and not just store it, you'll find this guide indispensable.

Table of Contents

  1. Access Data Analysis Cookbook
    1. SPECIAL OFFER: Upgrade this ebook with O’Reilly
    2. A Note Regarding Supplemental Files
    3. Preface
      1. Who Should Read This Book
      2. What's in This Book
      3. Conventions Used in This Book
      4. Using Code Examples
      5. We'd Like Your Feedback!
      6. Acknowledgments
        1. From Ken Bluttman
        2. From Wayne S. Freeze
    4. 1. Query Construction
      1. 1.1. Finding Unmatched Records
        1. 1.1.1. Problem
        2. 1.1.2. Solution
        3. 1.1.3. Discussion
        4. 1.1.4. See Also
      2. 1.2. Making AND and OR Do What You Expect
        1. 1.2.1. Problem
        2. 1.2.2. Solution
        3. 1.2.3. Discussion
      3. 1.3. Working with Criteria Using the IN Operator
        1. 1.3.1. Problem
        2. 1.3.2. Solution
        3. 1.3.3. Discussion
        4. 1.3.4. See Also
      4. 1.4. Excluding Records with the NOT Operator
        1. 1.4.1. Problem
        2. 1.4.2. Solution
        3. 1.4.3. Discussion
        4. 1.4.4. See Also
      5. 1.5. Parameterizing a Query
        1. 1.5.1. Problem
        2. 1.5.2. Solution
        3. 1.5.3. Discussion
          1. 1.5.3.1. Specifying a data type for the parameter
      6. 1.6. Returning a Top or Bottom Number of Records
        1. 1.6.1. Problem
        2. 1.6.2. Solution
        3. 1.6.3. Discussion
      7. 1.7. Returning Distinct Records
        1. 1.7.1. Problem
        2. 1.7.2. Solution
        3. 1.7.3. Discussion
          1. 1.7.3.1. Using DistinctRow
      8. 1.8. Returning Random Records
        1. 1.8.1. Problem
        2. 1.8.2. Solution
        3. 1.8.3. Discussion
      9. 1.9. Fine-Tuning Data Filtering with Subqueries
        1. 1.9.1. Problem
        2. 1.9.2. Solution
        3. 1.9.3. Discussion
          1. 1.9.3.1. Removing excessive queries
      10. 1.10. Combining Data with Union Queries
        1. 1.10.1. Problem
        2. 1.10.2. Solution
        3. 1.10.3. Discussion
      11. 1.11. Inserting On-the-Fly Fields in Select Queries
        1. 1.11.1. Problem
        2. 1.11.2. Solution
        3. 1.11.3. Discussion
      12. 1.12. Using Aliases to Simplify Your SQL Statements
        1. 1.12.1. Problem
        2. 1.12.2. Solution
        3. 1.12.3. Discussion
      13. 1.13. Creating a Left Join
        1. 1.13.1. Problem
        2. 1.13.2. Solution
        3. 1.13.3. Discussion
      14. 1.14. Creating a Right Join
        1. 1.14.1. Problem
        2. 1.14.2. Solution
        3. 1.14.3. Discussion
      15. 1.15. Creating an Outer Join
        1. 1.15.1. Problem
        2. 1.15.2. Solution
        3. 1.15.3. Discussion
        4. 1.15.4. See Also
    5. 2. Calculating with Queries
      1. 2.1. Finding the Sum or Average in a Set of Data
        1. 2.1.1. Problem
        2. 2.1.2. Solution
        3. 2.1.3. Discussion
      2. 2.2. Finding the Number of Items per Group
        1. 2.2.1. Problem
        2. 2.2.2. Solution
        3. 2.2.3. Discussion
      3. 2.3. Using Expressions in Queries
        1. 2.3.1. Problem
        2. 2.3.2. Solution
        3. 2.3.3. Discussion
      4. 2.4. Using Custom Functions in Queries
        1. 2.4.1. Problem
        2. 2.4.2. Solution
        3. 2.4.3. Discussion
      5. 2.5. Using Regular Expressions in Queries
        1. 2.5.1. Problem
        2. 2.5.2. Solution
        3. 2.5.3. Discussion
        4. 2.5.4. See Also
      6. 2.6. Using a Cartesian Product to Return All Combinations of Data
        1. 2.6.1. Problem
        2. 2.6.2. Solution
        3. 2.6.3. Discussion
      7. 2.7. Creating a Crosstab Query to View Complex Information
        1. 2.7.1. Problem
        2. 2.7.2. Solution
        3. 2.7.3. Discussion
          1. 2.7.3.1. Sophisticated crosstabs
    6. 3. Action Queries
      1. 3.1. Running an Update Query
        1. 3.1.1. Problem
        2. 3.1.2. Solution
        3. 3.1.3. Discussion
      2. 3.2. Appending Data
        1. 3.2.1. Problem
        2. 3.2.2. Solution
        3. 3.2.3. Discussion
          1. 3.2.3.1. Appending from a recordset
      3. 3.3. Deleting Data
        1. 3.3.1. Problem
        2. 3.3.2. Solution
        3. 3.3.3. Discussion
      4. 3.4. Creating Tables with Make-Table Queries
        1. 3.4.1. Problem
        2. 3.4.2. Solution
        3. 3.4.3. Discussion
    7. 4. Managing Tables, Fields, Indexes, and Queries
      1. 4.1. Creating Tables Programmatically
        1. 4.1.1. Problem
        2. 4.1.2. Solution
          1. 4.1.2.1. Using DAO to create a table
          2. 4.1.2.2. Using ADOX to create a table
          3. 4.1.2.3. Using SQL to create a table
          4. 4.1.2.4. Using an XSD schema definition to create a table
        3. 4.1.3. Discussion
          1. 4.1.3.1. Testing for the table's existence
          2. 4.1.3.2. Which method should you use?
      2. 4.2. Altering the Structure of a Table
        1. 4.2.1. Problem
        2. 4.2.2. Solution
          1. 4.2.2.1. Programmatically adding and deleting a field
          2. 4.2.2.2. Changing a field's data type
        3. 4.2.3. Discussion
      3. 4.3. Creating and Using an Index
        1. 4.3.1. Problem
        2. 4.3.2. Solution
        3. 4.3.3. Discussion
      4. 4.4. Programmatically Removing a Table
        1. 4.4.1. Problem
        2. 4.4.2. Solution
        3. 4.4.3. Discussion
      5. 4.5. Programmatically Creating a Query
        1. 4.5.1. Problem
        2. 4.5.2. Solution
        3. 4.5.3. Discussion
          1. 4.5.3.1. Creating action queries
    8. 5. Working with String Data
      1. 5.1. Returning Characters from the Left or Right Side of a String
        1. 5.1.1. Problem
        2. 5.1.2. Solution
        3. 5.1.3. Discussion
      2. 5.2. Returning Characters from the Middle of a String When the Start Position and Length Are Known
        1. 5.2.1. Problem
        2. 5.2.2. Solution
        3. 5.2.3. Discussion
      3. 5.3. Returning the Start Position of a Substring When the Characters Are Known
        1. 5.3.1. problem
        2. 5.3.2. Solution
        3. 5.3.3. Discussion
      4. 5.4. Stripping Spaces from the Ends of a String
        1. 5.4.1. Problem
        2. 5.4.2. Solution
        3. 5.4.3. Discussion
      5. 5.5. Stripping Spaces from the Middle of a String
        1. 5.5.1. Problem
        2. 5.5.2. Solution
        3. 5.5.3. Discussion
      6. 5.6. Replacing One String with Another String
        1. 5.6.1. Problem
        2. 5.6.2. Solution
        3. 5.6.3. Discussion
      7. 5.7. Concatenating Data
        1. 5.7.1. Problem
        2. 5.7.2. Solution
        3. 5.7.3. Discussion
          1. 5.7.3.1. Using the Join function
      8. 5.8. Sorting Numbers That Are Stored as Text
        1. 5.8.1. Problem
        2. 5.8.2. Solution
        3. 5.8.3. Discussion
      9. 5.9. Categorizing Characters with ASCII Codes
        1. 5.9.1. Problem
        2. 5.9.2. Solution
        3. 5.9.3. Discussion
    9. 6. Using Programming to Manipulate Data
      1. 6.1. Using Excel Functions from Access
        1. 6.1.1. Problem
        2. 6.1.2. Solution
        3. 6.1.3. Discussion
      2. 6.2. Working with In-Memory Data
        1. 6.2.1. Problem
        2. 6.2.2. Solution
        3. 6.2.3. Discussion
          1. 6.2.3.1. Using collections
      3. 6.3. Working with Multidimensional Arrays
        1. 6.3.1. Problem
        2. 6.3.2. Solution
        3. 6.3.3. Discussion
          1. 6.3.3.1. Working with three-dimensional data
      4. 6.4. Sorting an Array
        1. 6.4.1. Problem
        2. 6.4.2. Solution
        3. 6.4.3. Discussion
          1. 6.4.3.1. Sorting multidimensional arrays
      5. 6.5. Flattening Data
        1. 6.5.1. Problem
        2. 6.5.2. Solution
        3. 6.5.3. Discussion
      6. 6.6. Expanding Data
        1. 6.6.1. Problem
        2. 6.6.2. Solution
        3. 6.6.3. Discussion
      7. 6.7. Encrypting Data
        1. 6.7.1. Problem
        2. 6.7.2. Solution
        3. 6.7.3. Discussion
      8. 6.8. Applying Proximate Matching
        1. 6.8.1. Problem
        2. 6.8.2. Solution
        3. 6.8.3. Discussion
      9. 6.9. Using Transaction Processing
        1. 6.9.1. Problem
        2. 6.9.2. Solution
        3. 6.9.3. Discussion
      10. 6.10. Reading from and Writing to the Windows Registry
        1. 6.10.1. Problem
        2. 6.10.2. Solution
        3. 6.10.3. Discussion
      11. 6.11. Creating Charts
        1. 6.11.1. Problem
        2. 6.11.2. Solution
        3. 6.11.3. Discussion
          1. 6.11.3.1. Charts in Access 2007
      12. 6.12. Scraping Web HTML
        1. 6.12.1. Problem
        2. 6.12.2. Solution
        3. 6.12.3. Discussion
      13. 6.13. Creating Custom Report Formatting
        1. 6.13.1. Problem
        2. 6.13.2. Solution
        3. 6.13.3. Discussion
      14. 6.14. Rounding Values
        1. 6.14.1. Problem
        2. 6.14.2. Solution
        3. 6.14.3. Discussion
      15. 6.15. Running Word Mail Merges
        1. 6.15.1. Problem
        2. 6.15.2. Solution
        3. 6.15.3. Discussion
      16. 6.16. Building a Multifaceted Query Selection Screen
        1. 6.16.1. Problem
        2. 6.16.2. Solution
        3. 6.16.3. Discussion
    10. 7. Importing and Exporting Data
      1. 7.1. Creating an Import/Export Specification
        1. 7.1.1. Problem
        2. 7.1.2. Solution
        3. 7.1.3. Discussion
      2. 7.2. Automating Imports and Exports
        1. 7.2.1. Problem
        2. 7.2.2. Solution
        3. 7.2.3. Discussion
      3. 7.3. Exporting Data with the FileSystemObject
        1. 7.3.1. Problem
        2. 7.3.2. Solution
        3. 7.3.3. Discussion
      4. 7.4. Importing Data with the FileSystemObject
        1. 7.4.1. Problem
        2. 7.4.2. Solution
        3. 7.4.3. Discussion
      5. 7.5. Importing and Exporting Using XML
        1. 7.5.1. Problem
        2. 7.5.2. Solution
        3. 7.5.3. Discussion
      6. 7.6. Generating XML Schemas
        1. 7.6.1. Problem
        2. 7.6.2. Solution
        3. 7.6.3. Discussion
      7. 7.7. Using XSLT on Import or Export
        1. 7.7.1. Problem
        2. 7.7.2. Solution
        3. 7.7.3. Discussion
      8. 7.8. Working with XML via the MSXML Parser
        1. 7.8.1. Problem
        2. 7.8.2. Solution
        3. 7.8.3. Discussion
      9. 7.9. Reading and Writing XML Attributes
        1. 7.9.1. Problem
        2. 7.9.2. Solution
        3. 7.9.3. Discussion
      10. 7.10. Creating an RSS Feed
        1. 7.10.1. Problem
        2. 7.10.2. Solution
        3. 7.10.3. Discussion
      11. 7.11. Passing Parameters to SQL Server
        1. 7.11.1. Problem
        2. 7.11.2. Solution
        3. 7.11.3. Discussion
      12. 7.12. Handling Returned Values from SQL Server Stored Procedures
        1. 7.12.1. Problem
        2. 7.12.2. Solution
        3. 7.12.3. Discussion
      13. 7.13. Working with SQL Server Data Types
        1. 7.13.1. Problem
        2. 7.13.2. Solution
        3. 7.13.3. Discussion
      14. 7.14. Handling Embedded Quotation Marks
        1. 7.14.1. Problem
        2. 7.14.2. Solution
        3. 7.14.3. Discussion
      15. 7.15. Importing Appointments from the Outlook Calendar
        1. 7.15.1. Problem
        2. 7.15.2. Solution
        3. 7.15.3. Discussion
      16. 7.16. Importing Emails from Outlook
        1. 7.16.1. Problem
        2. 7.16.2. Solution
        3. 7.16.3. Discussion
      17. 7.17. Working with Outlook Contacts
        1. 7.17.1. Problem
        2. 7.17.2. Solution
        3. 7.17.3. Discussion
      18. 7.18. Importing Data from Excel
        1. 7.18.1. Problem
        2. 7.18.2. Solution
        3. 7.18.3. Discussion
      19. 7.19. Exporting Data to Excel
        1. 7.19.1. Problem
        2. 7.19.2. Solution
        3. 7.19.3. Discussion
      20. 7.20. Talking to PowerPoint
        1. 7.20.1. Problem
        2. 7.20.2. Solution
        3. 7.20.3. Discussion
      21. 7.21. Selecting Random Data
        1. 7.21.1. Problem
        2. 7.21.2. Solution
        3. 7.21.3. Discussion
    11. 8. Date and Time Calculations
      1. 8.1. Counting Elapsed Time
        1. 8.1.1. Problem
        2. 8.1.2. Solution
        3. 8.1.3. Discussion
      2. 8.2. Counting Elapsed Time with Exceptions
        1. 8.2.1. Problem
        2. 8.2.2. Solution
        3. 8.2.3. Discussion
      3. 8.3. Working with Time Zones
        1. 8.3.1. Problem
        2. 8.3.2. Solution
        3. 8.3.3. Discussion
      4. 8.4. Working Around Leap Years
        1. 8.4.1. Problem
        2. 8.4.2. Solution
        3. 8.4.3. Discussion
      5. 8.5. Isolating the Day, Month, or Year
        1. 8.5.1. Problem
        2. 8.5.2. Solution
        3. 8.5.3. Discussion
      6. 8.6. Isolating the Hour, Minute, or Second
        1. 8.6.1. Problem
        2. 8.6.2. Solution
        3. 8.6.3. Discussion
      7. 8.7. Adding Time
        1. 8.7.1. Problem
        2. 8.7.2. Solution
        3. 8.7.3. Discussion
    12. 9. Business and Finance Problems
      1. 9.1. Calculating Weighted Averages
        1. 9.1.1. Problem
        2. 9.1.2. Solution
        3. 9.1.3. Discussion
      2. 9.2. Calculating a Moving Average
        1. 9.2.1. Problem
        2. 9.2.2. Solution
        3. 9.2.3. Discussion
      3. 9.3. Calculating Payback Period
        1. 9.3.1. Problem
        2. 9.3.2. Solution
        3. 9.3.3. Discussion
      4. 9.4. Calculating Return on Investment
        1. 9.4.1. Problem
        2. 9.4.2. Solution
        3. 9.4.3. Discussion
      5. 9.5. Calculating Straight-Line Depreciation
        1. 9.5.1. Problem
        2. 9.5.2. Solution
        3. 9.5.3. Discussion
      6. 9.6. Creating a Loan Payment Schedule
        1. 9.6.1. Problem
        2. 9.6.2. Solution
        3. 9.6.3. Discussion
      7. 9.7. Using PivotTables and PivotCharts
        1. 9.7.1. Problem
        2. 9.7.2. Solution
        3. 9.7.3. Discussion
        4. 9.7.4. See Also
      8. 9.8. Creating PivotTables
        1. 9.8.1. Problem
        2. 9.8.2. Solution
        3. 9.8.3. Discussion
      9. 9.9. Charting Data
        1. 9.9.1. Problem
        2. 9.9.2. Solution
        3. 9.9.3. Discussion
      10. 9.10. Finding Trends
        1. 9.10.1. Problem
        2. 9.10.2. Solution
        3. 9.10.3. Discussion
      11. 9.11. Finding Head and Shoulders Patterns
        1. 9.11.1. Problem
        2. 9.11.2. Solution
        3. 9.11.3. Discussion
      12. 9.12. Working with Bollinger Bands
        1. 9.12.1. Problem
        2. 9.12.2. Solution
        3. 9.12.3. Discussion
      13. 9.13. Calculating Distance Between Zip Codes
        1. 9.13.1. Problem
        2. 9.13.2. Solution
        3. 9.13.3. Discussion
    13. 10. Statistics
      1. 10.1. Creating a Histogram
        1. 10.1.1. Problem
        2. 10.1.2. Solution
        3. 10.1.3. Discussion
      2. 10.2. Finding and Comparing the Mean, Mode, and Median
        1. 10.2.1. Problem
        2. 10.2.2. Solution
        3. 10.2.3. Discussion
      3. 10.3. Calculating the Variance in a Set of Data
        1. 10.3.1. Problem
        2. 10.3.2. Solution
        3. 10.3.3. Discussion
      4. 10.4. Finding the Covariance of Two Data Sets
        1. 10.4.1. Problem
        2. 10.4.2. Solution
        3. 10.4.3. Discussion
      5. 10.5. Finding the Correlation of Two Sets of Data
        1. 10.5.1. Problem
        2. 10.5.2. Solution
        3. 10.5.3. Discussion
      6. 10.6. Returning All Permutations in a Set of Data
        1. 10.6.1. Problem
        2. 10.6.2. Solution
        3. 10.6.3. Discussion
      7. 10.7. Returning All Combinations in a Set of Data
        1. 10.7.1. Problem
        2. 10.7.2. Solution
        3. 10.7.3. Discussion
      8. 10.8. Calculating the Frequency of a Value in a Set of Data
        1. 10.8.1. Problem
        2. 10.8.2. Solution
        3. 10.8.3. Discussion
      9. 10.9. Generating Growth Rates
        1. 10.9.1. Problem
        2. 10.9.2. Solution
        3. 10.9.3. Discussion
      10. 10.10. Determining the Probability Mass Function for a Set of Data
        1. 10.10.1. Problem
        2. 10.10.2. Solution
        3. 10.10.3. Discussion
      11. 10.11. Computing the Kurtosis to Understand the Peakedness or Flatness of a Probability Mass Distribution
        1. 10.11.1. Problem
        2. 10.11.2. Solution
        3. 10.11.3. Discussion
      12. 10.12. Determining the Skew of a Set of Data
        1. 10.12.1. Problem
        2. 10.12.2. Solution
        3. 10.12.3. Discussion
      13. 10.13. Returning a Range of Data by Percentile
        1. 10.13.1. Problem
        2. 10.13.2. Solution
        3. 10.13.3. Discussion
      14. 10.14. Determining the Rank of a Data Item
        1. 10.14.1. Problem
        2. 10.14.2. Solution
        3. 10.14.3. Discussion
      15. 10.15. Determining the Slope and the Intercept of a Linear Regression
        1. 10.15.1. Problem
        2. 10.15.2. Solution
        3. 10.15.3. Discussion
      16. 10.16. Measuring Volatility
        1. 10.16.1. Problem
        2. 10.16.2. Solution
        3. 10.16.3. Discussion
    14. Index
    15. About the Authors
    16. Colophon
    17. SPECIAL OFFER: Upgrade this ebook with O’Reilly