HandsOn Writing a Function Procedure with Arguments

This chapter's hands-on exercises are provided in the Acc2003_Chap04.mdb file included in the book's downloadable files.

1. Open Acc2003_Chap04.mdb from the downloadable files or, if you'd like to start from scratch, create a new Access 2003 database.

2. In the Database window, click the Module button to create a new module.

3. Enter the following function procedure JoinText in the Module1 Code window.

Function JoinText(k, o)

Note that there is a space character in quotation marks concatenated between the two arguments of the JoinText function's result: JoinText = k + " " + o.

A better way of adding a space is by using one of the built-in functions as shown below:

Introduction to Access 2003 VBA Programming

The Space function returns a string of spaces consisting of the number of spaces indicated in the parentheses. The Chr function returns a string containing the character associated with the specified character code.

Other control characters you may need to use when writing your VBA procedures are listed below:

You can execute a function procedure from the Immediate window, or you can write a subroutine to call the function. See Hands-On 4-2 for how to run the JoinText function procedure.

0 0

Post a comment