IN THIS CHAPTER
What Are Functions? |
37 |
Converting Data Types |
38 |
Working with Date Functions |
42 |
Using Mathematical Functions |
48 |
Using Financial Functions |
50 |
Manipulating Text Strings |
52 |
Formatting Values |
55 |
Domain Aggregate Functions |
59 |
Using the Is Functions |
61 |
Interaction |
61 |
Case Study: Add Work Days |
64 |
What Are Functions?
Built-in functions are commands provided by Access and VBA that return a value. The value returned is dependent on the purpose of the function and the arguments, if any, passed to it. VBA is rich in functions that perform a variety of tasks and calculations for you. There are functions to convert data types, perform calculations on dates, perform simple to complex mathematics, make financial calculations, manage text strings, format values, and retrieve data from tables, among others.
Functions return a value, and most accept arguments to act on. A lot of your code will use functions to make calculations and manipulate data. You should familiarize yourself with the functions that VBA makes available to you, but don't expect to memorize their syntax. Between Intellisense and the VBA Help screens you can't go far off course, especially because Intellisense prompts you for each argument. If you need help understanding an argument, press F1 or look up the function in VBA Help.
Although this book was not meant to be a reference for VBA functions, this chapter explains many of the most used ones to give you an idea of VBA's power.
A point to remember when coding your functions: Be consistent in using data types. If you provide arguments of the wrong data type or assign a function to a different data type, you will cause an error.