

An Integer is another number data type, but its value must be between -32,768 and 32,767, and it must be a whole number, that is to say, it mustn’t contain decimal places. Sub trueOrFalse()Īt the beginning of the post we said that we have to tell the computer what type of data to expect before we can work on it.

Notice we used capitalised words for True and False, which is because they are VBA keywords and you cannot name a variable a Keyword. In VBA you can assign a Boolean variable to True (-1) or False (0) or the numbers indicated in the brackets. These are often thought of as states and correspond to Access’s Yes/No fields.
#Microsoft access data types explained code
VBA is case- ‘ insensitive, variables also cannot be ‘ declared more than once in a code blockĭim aVariableName as String ‘ a valid variable nameĭim a_Variable_Name as String ‘ a valid variable nameĭim HELLOWORLD as String ‘ a valid variable nameĭim dim as String ‘ variable name is invalid as Dim is a keywordĪ variable of type Boolean is the simplest possible data type available in VBA. Sub Declarations()ĭim _b as String ‘ variable names must start with a letterĭim 2b as String ‘ variable names must start with a letterĭim d12 as String ‘ a valid variable nameĭim e_e1 as String ‘ a valid variable nameĭim f! as String ‘ punctuation not allowed in variable namesĭim G as String ‘ an invalid variable name. Also unlike other languages VBA is case-insensitive! This is important to understand and is demonstrated below.įinally, there are some keywords that cannot be used as variable names. Variable names must start with a letter, may contain number characters or underscores ( _ ) but that’s it! Punctuation marks are not allowed. In this blog post we explain data types in VBA and provide detailed definitions for when they should be used.įirstly a word on VBA variable names a variable may be named anything you wish as long as it conforms to VBA’s naming rules.
