Microsoft Office Tutorials and References
In Depth Information
Writing Your Own VBA Procedures
The name of the new procedure is a combination of the control’s name and
the event that triggers the procedure. The name is the one that appears at the
top of the All tab of the property sheet. If you right-click a button named
MyButton and then build the procedure from the On Click event on the
Event tab of the property sheet, the procedure looks like this:
Private Sub MyButton_Click()
End Sub
Passing arguments to procedures
When you create your own expressions in Access, you often use built-in
functions that are capable of accepting arguments. A built-in UCase()
function, for example, takes any string of text as an argument. The argument is
text that you hand over to the function to operate on. The function does its
thing on the argument and then returns the results.
To pass an argument to a built-in function, you place it in the parentheses
after the function name. If you’re passing a literal string, you must enclose
that string in quotation marks. Suppose that you type the following in the
Immediate window of Visual Basic Editor:
? UCase(“howdy world”)
In this example, UCase() is the function, and “howdy world” is the
argument — the value being passed to the function. The UCase() function
returns that same chunk of text with all the letters converted to uppercase:
HOWDY WORLD.
When you create your own procedures, you can define what arguments, if
any, the procedure is capable of accepting. If you create a function
procedure, you can also define what the procedure returns. (A sub procedure
doesn’t return a value.)
If you look at the syntax chart for the Sub statement and take away some of
the optional stuff from that chart, you see that the syntax for the Sub
statement looks something like this:
Sub name [( arglist )]
End Sub
 
Search JabSto ::




Custom Search