Visual Basic for Applications

From vb24
Jump to navigation Jump to search

General

Conventions

Concepts

Code

Problems and solutions

Double code execution

Problem
The function provided with the OnAction property is executed twice.
Solution
Put the function name in single quotes:
.OnAction="'functionname'"

Corrupt Microsoft Access database

Problem
Microsoft Access gives strange errors, when trying to compile the project.
Solution
Decompile your database

Tricks

Keywords

If you need to use keywords in an enumeration, for example, you can escape the keyword check with square brackets:

Public Enum Keyword
    [Boolean] = 1
    [Integer] = 2
    [String] = 3
End Enum

As whenever you push the limits of a language, there is always a downside, which needs to be considered carefully: user defined keywords usually have precedence over system keywords. So if you specify, for example, an enumeration with Array as keyword, you will need to either specify any occurrence of the Array function with the corresponding parental object or you will receive errors like "data field expected".