Cover image for Access Cookbook

Book description

Access Cookbook contains a comprehensive collection of problems, solutions,and practical examples for the Access power user or programmer who is running up against some of the apparent limits of the Access user interface or of Access application development. The diverse problems and solutions presented here are of interest to Access power users and programmers at all levels, from the relatively inexperienced to the most sophisticated. Each of the book?s 14 chapters focuses on a particular topic area related to the Access environment or Access programming. Within each chapter, individual items follow a standardized format. The authors first pose the problem, and then present its solution. Finally, a discussion follows, which consists of extended analysis of the solution, an insightful examination of how Access works, or interesting programming techniques that are used in the solution but that you can also apply elsewhere. The kinds of problems posed and solved in the book include the following:

  • Specifying query criteria at runtime, rather than at design time

  • Restricting the user to a single row of a form

  • Preventing a report from printing if it has no records

  • Making slow forms run faster

  • Insuring that user interface objects present a uniform, consistent appearance

  • Controlling a printer's paper source programmatically

  • Referencing data from multiple SQL Server databases in a single Access Data Project page

  • Using contact information from an Access database when sending email using Outlook

The accompanying CD-ROM includes Access databases that contain the solutions for all problems presented in the text.

Table of Contents

  1. Access Cookbook
    1. Preface
      1. What This Book Is About
        1. Promotes Creative Use of the Product
        2. Uses the Tools at Hand
        3. Question-and-Answer Format
      2. Who This Book Is For
      3. What You Need to Use This Book
      4. How This Book Is Organized
      5. What We Left Out
        1. How Do I Set Control Properties?
        2. How Do I Create a New Module?
        3. How Do I Import an Object?
        4. How Do I Create an Event Macro?
        5. How Do I Create an Event Procedure?
        6. How Do I Place Code in a Form or Report’s Module?
        7. How Do I Know What to Do with Code Examples?
      6. Conventions Used in This Book
      7. Comments and Questions
      8. Acknowledgments
    2. 1. Queries
      1. Specify Query Criteria at Runtime
        1. Problem
        2. Solution
        3. Discussion
      2. Using a Form-Based Parameter Query
        1. Problem
        2. Solution
        3. Discussion
      3. Limit the Items in One Combo Box Based on the Selected Item in Another
        1. Problem
        2. Solution
        3. Discussion
      4. Make Formatted Date Columns Sort Correctly in a Crosstab Query
        1. Problem
        2. Solution
        3. Discussion
      5. Group Mailing Labels by Address
        1. Problem
        2. Solution
        3. Discussion
      6. Use a Field in One Table to Update a Field in Another Table
        1. Problem
        2. Solution
        3. Discussion
      7. Use a VBA Variable to Filter a Query
        1. Problem
        2. Solution
        3. Discussion
      8. Use a Query to Retrieve a Random Set of Rows
        1. Problem
        2. Solution
        3. Discussion
      9. Create a Query That Will Show Aging of Receivables
        1. Problem
        2. Solution
        3. Discussion
      10. Create a Join That’s Based on a Comparison Other than Equality
        1. Problem
        2. Solution
        3. Discussion
      11. Create a Query to Combine Data from Two Tables with Similar Structures
        1. Problem
        2. Solution
        3. Discussion
      12. Create a Combo Box That Allows a User to Select N/A
        1. Problem
        2. Solution
        3. Discussion
      13. Use a Query to Show the Relationship Between Employees and Supervisors
        1. Problem
        2. Solution
        3. Discussion
      14. Create a Query That Uses Case-Sensitive Criteria
        1. Problem
        2. Solution
        3. Discussion
      15. Use a Query to Create a New Table Complete with Indexes
        1. Problem
        2. Solution
        3. Discussion
      16. Save My Queries in a Table for Better Programmatic Access and Security
        1. Problem
        2. Solution
        3. Discussion
      17. Create a Recordset Based on a Parameter Query from VBA Code
        1. Problem
        2. Solution
        3. Discussion
    3. 2. Forms
      1. Make Custom Templates for Forms and Reports
        1. Problem
        2. Solution
        3. Discussion
      2. Highlight the Current Field in Data-Entry Forms
        1. Problem
        2. Solution
        3. Discussion
      3. Restrict the User to a Single Row on a Form
        1. Problem
        2. Solution
        3. Discussion
      4. Use an Option Group to Collect and Display Textual Information
        1. Problem
        2. Solution
        3. Discussion
      5. Display Multiple Pages of Information on One Form
        1. Problem
        2. Solution
        3. Discussion
      6. Provide Record Navigation Buttons on a Form
        1. Problem
        2. Solution
        3. Discussion
      7. Size a Form’s Controls to Match the Form’s Size
        1. Problem
        2. Solution
        3. Discussion
      8. Make a Simple “Searching” List Box
        1. Problem
        2. Solution
        3. Discussion
      9. Create a Replacement for Access’s InputBox
        1. Problem
        2. Solution
        3. Discussion
          1. Using optional parameters
          2. Creating pop-up forms
          3. Initializing pop-up forms
          4. Programmatically accessing online help
          5. Miscellaneous comments
      10. Store the Sizes and Locations of Forms
        1. Problem
        2. Solution
        3. Discussion
      11. Open Multiple Instances of a Form
        1. Problem
        2. Solution
        3. Discussion
    4. 3. Reports
      1. Create a Report with Line Numbers
        1. Problem
        2. Solution
        3. Discussion
      2. Print the Value of a Parameter on a Report
        1. Problem
        2. Solution
        3. Discussion
      3. Create a Report with Multiple Columns
        1. Problem
        2. Solution
        3. Discussion
      4. Print a Message on a Report if Certain Conditions Are Met
        1. Problem
        2. Solution
        3. Discussion
      5. Create a Page-Range Indicator on Each Page
        1. Problem
        2. Solution
        3. Discussion
      6. Create a Simple Bar Graph on a Report
        1. Problem
        2. Solution
        3. Discussion
      7. Create a Page Total
        1. Problem
        2. Solution
        3. Discussion
      8. Avoid Unwanted Blank Rows on Mailing Labels
        1. Problem
        2. Solution
        3. Discussion
      9. Suppress Printing a Report if There Are No Records to Print
        1. Problem
        2. Solution
        3. Discussion
      10. Print Different Headers or Footers on Odd and Even Pages
        1. Problem
        2. Solution
        3. Discussion
      11. Make a Vertical Line the Same Height as a CanGrow/CanShrink Control
        1. Problem
        2. Solution
        3. Discussion
      12. Alternate Gray Bars on My Reports
        1. Problem
        2. Solution
        3. Discussion
      13. Print Only Records Matching a Form’s Filter
        1. Problem
        2. Solution
        3. Discussion
      14. Keep a Report from Breaking at an Inappropriate Place
        1. Problem
        2. Solution
        3. Discussion
      15. Customize a Report’s Grouping and Sorting at Runtime
        1. Problem
        2. Solution
        3. Discussion
    5. 4. Developing and Distributing Applications
      1. Convert Queries into Embedded SQL Statements
        1. Problem
        2. Solution
        3. Discussion
      2. Build an Object Inventory
        1. Problem
        2. Solution
        3. Discussion
          1. Documenting all the containers
          2. Creating the inventory table
          3. Documenting each container
          4. Avoiding errors
          5. Comments
      3. Verify That Objects Use Consistent Settings
        1. Problem
        2. Solution
        3. Discussion
          1. Creating the temporary tables and query
          2. Getting ready to document items
          3. Visiting all the objects
          4. Recording property information
          5. Comments
      4. Hide Access Screen Activity
        1. Problem
        2. Solution
        3. Discussion
          1. Hiding reports in design view
          2. Beware the pitfalls!
      5. Find out What Language Version of Access Is Installed
        1. Problem
        2. Solution
        3. Discussion
      6. Internationalize Text in Your Applications
        1. Problem
        2. Solution
        3. Discussion
      7. Change and Reset the Access Caption Bar
        1. Problem
        2. Solution
        3. Discussion
      8. Use the Windows File Open/Save Common Dialogs
        1. Problem
        2. Solution
        3. Discussion
      9. Clean Test Data out of a Database When You’re Ready to Ship It
        1. Problem
        2. Solution
        3. Discussion
      10. Secure Your Access Database
        1. Problem
        2. Solution
        3. Discussion
    6. 5. Taming Your Printer
      1. Retrieve a List of All the Installed Output Devices
        1. Problem
        2. Solution
        3. Discussion
          1. Adding items to a list box
      2. Set and Retrieve the Name of the Default Output Device
        1. Problem
        2. Solution
        3. Discussion
      3. Programmatically Change Margin and Column Settings for Reports
        1. Problem
        2. Solution
        3. Discussion
      4. Programmatically Change Printer Options
        1. Problem
        2. Solution
        3. Discussion
      5. Programmatically Control the Paper Source
        1. Problem
        2. Solution
        3. Discussion
      6. Retrieve Information About a Report or Form’s Selected Printer
        1. Problem
        2. Solution
      7. Choose an Output Device at Runtime
        1. Problem
        2. Solution
        3. Discussion
      8. Find Which Reports Are Not Set to Print to the Default Printer
        1. Problem
        2. Solution
        3. Discussion
    7. 6. Managing Data
      1. Save with Each Record the Name of the Last Person Who Edited It and the Date and Time
        1. Problem
        2. Solution
        3. Discussion
      2. Determine if You’re on a New Record in a Form
        1. Problem
        2. Solution
        3. Discussion
      3. Find All Records with Names That Sound Alike
        1. Problem
        2. Solution
        3. Discussion
      4. Find the Median Value for a Field
        1. Problem
        2. Solution
        3. Discussion
      5. Quickly Find a Record in a Linked Table
        1. Problem
        2. Solution
        3. Discussion
      6. Get a Complete List of Field Properties from a Table or Query
        1. Problem
        2. Solution
        3. Discussion
      7. Create and Use Flexible AutoNumber Fields
        1. Problem
        2. Solution
        3. Discussion
      8. Back Up Selected Objects to Another Database
        1. Problem
        2. Solution
        3. Discussion
          1. The MultiSelect property
          2. Filling the lboObjects list box
          3. The backup process
          4. Comments
    8. 7. Exploring VBA in Microsoft Access
      1. Build Up String References with Embedded Quotes
        1. Problem
        2. Solution
        3. Discussion
      2. Create a Global Procedure Stack
        1. Problem
        2. Solution
        3. Discussion
      3. Create an Execution Time Profiler
        1. Problem
        2. Solution
        3. Steps
        4. Discussion
      4. Multitask Your Access Basic Code
        1. Problem
        2. Solution
        3. Discussion
      5. Programmatically Add Items to a List or Combo Box
        1. Problem
        2. Solution
          1. Filling a list box by modifying the RowSource property
          2. Filling a list box by creating a list-filling callback function
        3. Discussion
          1. Modifying the RowSource property
          2. Creating a list-filling callback function
      6. Pass a Variable Number of Parameters to a Procedure
        1. Problem
        2. Solution
        3. Discussion
      7. Sort an Array in Access Basic
        1. Problem
        2. Solution
        3. Discussion
      8. Fill a List Box with a List of Files
        1. Problem
        2. Solution
        3. Discussion
      9. Handle Object Properties, in General
        1. Problem
        2. Solution
        3. Discussion
      10. Detect Whether an Object Exists
        1. Problem
        2. Solution
        3. Discussion
    9. 8. Optimizing Your Application
      1. Accelerate the Load Time of Forms
        1. Problem
        2. Solution
        3. Discussion
      2. Make Slow Forms Run Faster
        1. Problem
        2. Solution
          1. Graphic and memo controls
          2. Combo and list box controls
        3. Discussion
      3. Make Combo Boxes Load Faster
        1. Problem
        2. Solution
        3. Discussion
      4. Use Rushmore to Speed Up Queries
        1. Problem
        2. Solution
        3. Discussion
      5. Accelerate VBA Code
        1. Problem
        2. Solution
        3. Discussion
      6. Test the Comparative Benefits of Various Optimization Techniques
        1. Problem
        2. Solution
        3. Discussion
      7. Accelerate Multiuser Applications
        1. Problem
        2. Solution
        3. Discussion
      8. Accelerate Client/Server Applications
        1. Problem
        2. Solution
        3. Discussion
    10. 9. Making the Most of Your User Interface
      1. Create Context-Sensitive Keyboard Shortcuts
        1. Problem
        2. Solution
        3. Discussion
      2. Create a Form with No Menu or Toolbar
        1. Problem
        2. Solution
        3. Discussion
      3. Create a Geographical Map Interface
        1. Problem
        2. Solution
        3. Discussion
      4. Mark a Record on a Form and Return to It Later
        1. Problem
        2. Solution
        3. Discussion
      5. Carry Data Forward from Record to Record
        1. Problem
        2. Solution
        3. Discussion
      6. Create a Combo Box That Accepts New Entries
        1. Problem
        2. Solution
        3. Discussion
      7. Create Animated Buttons
        1. Problem
        2. Solution
          1. Two-state buttons
          2. Continuously animated buttons
        3. Discussion
      8. Create an Expanding Dialog
        1. Problem
        2. Technique
        3. Discussion
      9. Use an ActiveX Control
        1. Problem
        2. Solution
          1. Add a bound Calendar control to your form
          2. Create a generic unbound pop-up calendar form
        3. Discussion
      10. Create a Generic, Reusable Status Meter
        1. Problem
        2. Solution
          1. Create a generic status meter
          2. Use the generic status meter in your application
        3. Discussion
    11. 10. Multiuser Applications
      1. Properly Secure Your Database
        1. Problem
        2. Solution
          1. Make a security plan
          2. Secure your database
          3. Work with the secured database
        3. Discussion
      2. Maintain Multiple Synchronized Copies of the Same Database
        1. Problem
        2. Solution
          1. Replicating a database
          2. Synchronizing replicas
          3. Resolving conflicts
        3. Discussion
      3. Create a Transaction Log
        1. Problem
        2. Solution
        3. Discussion
      4. Send Messages to Other Users Without Using Email
        1. Problem
        2. Solution
        3. Discussion
      5. Programmatically Track Users and Groups
        1. Problem
        2. Solution
        3. Discussion
      6. Adjust an Application Based on Who’s Logged In
        1. Problem
        2. Solution
        3. Discussion
      7. List All Users with Blank Passwords
        1. Problem
        2. Solution
        3. Discussion
      8. Track Which Users Have a Shared Database Open
        1. Problem
        2. Solution
        3. Discussion
      9. Determine if a Record Is Locked and by Whom
        1. Problem
        2. Solution
        3. Discussion
      10. Set a Maximum Locking Interval for a Record
        1. Problem
        2. Solution
        3. Discussion
    12. 11. The Windows API
      1. Remove a Form’s System Menu and Maximize/Minimize Buttons
        1. Problem
        2. Solution
        3. Discussion
      2. Flash a Window’s Titlebar or Icon
        1. Problem
        2. Solution
        3. Discussion
      3. Classify Keypresses in a Language-Independent Manner
        1. Problem
        2. Solution
        3. Discussion
      4. Restrict Mouse Movement to a Specific Region
        1. Problem
        2. Solution
        3. Discussion
      5. Run Another Program and Pause Until It’s Done
        1. Problem
        2. Solution
        3. Discussion
      6. Exit Windows Under Program Control
        1. Problem
        2. Solution
        3. Discussion
      7. Run the Application Associated with a Data File
        1. Problem
        2. Solution
        3. Discussion
      8. Check to See if an Application Is Already Running
        1. Problem
        2. Solution
        3. Discussion
      9. Retrieve a List of All Top-Level Windows
        1. Problem
        2. Solution
        3. Discussion
      10. Close a Running Windows Application
        1. Problem
        2. Solution
        3. Discussion
      11. Set File Date and Time Stamps
        1. Problem
        2. Solution
        3. Discussion
      12. Retrieve Information About Available Drives
        1. Problem
        2. Solution
        3. Discussion
      13. Collect and Display Information on the System and the Access Installation
        1. Problem
        2. Solution
        3. Discussion
      14. Create and Cancel Network Connections Programmatically
        1. Problem
        2. Solution
        3. Discussion
          1. Retrieving information
          2. Adding and canceling connections using common dialogs
          3. Adding and canceling connections with no user intervention
    13. 12. Automation
      1. Play an Embedded Sound File from Within an Application
        1. Problem
        2. Solution
        3. Discussion
      2. Print an Access Report from Excel
        1. Problem
        2. Solution
        3. Discussion
      3. Use Excel’s Functions from Within Access
        1. Problem
        2. Solution
        3. Discussion
          1. Setting up communication with Excel
          2. Calling simple Excel functions
          3. Calling Excel functions using ranges
          4. Calling Excel functions using arrays
          5. Closing Excel
        4. Comments
      4. Perform a Mail Merge from Access to Word
        1. Problem
        2. Solution
        3. Discussion
          1. Starting the connection with Word for Windows
          2. Performing the mail merge
          3. Finishing the mail merge
      5. Add an Item to the Startup Group
        1. Problem
        2. Solution
          1. Using the sample forms
          2. Using DDE with the Windows shell
        3. Discussion
          1. Retrieving information from the Windows shell
          2. Executing tasks
          3. Using the wrapper procedures
        4. Comments
      6. Send Access Data to Excel and Create an Excel Chart
        1. Problem
        2. Solution
        3. Discussion
      7. Create a PowerPoint Presentation from Access Data
        1. Problem
        2. Solution
        3. Discussion
          1. Starting and stopping PowerPoint
          2. Creating the presentation
          3. Creating each slide
          4. Creating the text
        4. Comments
      8. Add a Contact and Send Email Through Outlook
        1. Problem
        2. Solution
        3. Discussion
    14. 13. Using Data Access Pages
      1. Replace Navigation Button Images with Your Own Images
        1. Problem
        2. Solution
        3. Discussion
      2. Use Labels or Other Controls for Record Navigation
        1. Problem
        2. Solution
      3. Change the Text Displayed with a Navigation Control
        1. Problem
        2. Solution
      4. Create a DAP That Allows You to Update Data
        1. Problem
        2. Solution
      5. Create One File to Store Connection Information for All DAPs in an Application
        1. Problem
        2. Solution
      6. Programmatically Change the Connection String for All Pages in a Database
        1. Problem
        2. Solution
        3. Discussion
      7. Change the Default Settings for New DAPs
        1. Problem
        2. Solution
        3. Discussion
      8. Use Parameters Set in One DAP to Open Another
        1. Problem
        2. Solution
        3. Discussion
    15. 14. Working with SQL Server Data
      1. Dynamically Link SQL Server Tables at Runtime
        1. Problem
        2. Solution
        3. Discussion
      2. Dynamically Connect to SQL Server from an ADP
        1. Problem
        2. Solution
        3. Discussion
      3. Share an ADP from a Shared Network Folder
        1. Problem
        2. Solution
        3. Discussion
      4. Fill the Drop-Down Lists When Using ServerFilterByForm in an ADP
        1. Problem
        2. Solution
        3. Discussion
      5. Pass Parameters to Stored Procedures from Pass-Through Queries in an MDB
        1. Problem
        2. Solution
        3. Discussion
      6. Pass Parameters to Stored Procedures from an ADP
        1. Problem
        2. Solution
        3. Discussion
      7. Use Controls as Parameters for the Row Source of Combo and List Boxes in an ADP
        1. Problem
        2. Solution
        3. Discussion
      8. Reference Data from More than One SQL Server Database in an ADP
        1. Problem
        2. Solution
        3. Discussion
      9. Use Views to Update Data in an ADP When Users Don’t Have Permissions on Tables
        1. Problem
        2. Solution
        3. Discussion
    16. Index
    17. Colophon