Appendix A. Programming Tips and Tricks
This appendix contains some useful tips and tricks that you can use in your applications. Many of these code snippets are ones we have used over the years to help standardize our code or represent specific problems that we were trying to solve. Several of the techniques were born out of refactoring efforts to help make code more elegant. Refactoring is the process of making code more readable or simplified without changing the end result.
This appendix also covers such topics as running code dynamically and working with objects and dates. The appendix ends with some cool tools that you can add to your applications to make the process of writing code easier.
Dynamically Running Code
In many cases, you may want to run code dynamically — in other words, where the name of the routine that you want to execute is not known until runtime. For example, in Chapter 8 we used the Eval
function to pass the name of a routine that was stored in a table for custom navigation in the application. VBA and the Access object model provides three mechanisms to do this: CallByName, Eval
, and Application.Run
.
CallByName
The CallByName
function is defined by VBA and is used to invoke a property or method on an object instance. It can also be used to set a property value for an object instance. The parameters for the CallByName
function are listed in the table that follows.
Parameter Name | Parameter Type | Description |
---|---|---|
|
| An instance of an object whose property or method ... |
Get Expert Access™ 2007 Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.