Microsoft Access Field Data Type Reference

April 30, 2013 in Microsoft Access

This page lists every possible field data type that a native Access (Access Database Engine) database can contain. It also shows which methods can be used to create fields of the given type. The information here applies to Access 2007+ (the ACE engine) but most information holds true for earlier versions as well. Contents List of Data Types Examining Data Types Creating Fields, by Data Type List of Microsoft Access Data Types Types of Types Officially, there are 13 primary data types in Microsoft Access. See SQL Data Types. There a number of subtypes, however, depending on how an individual
…read more

Arrays in VBA – Part 2: Array Assignment Rules

April 29, 2013 in VBA

Arrays are powerful tools in VBA. However, the many types of arrays and the fact that in VBA arrays are value types means that assigning array variables is tricky business. In this post I’ll explain all the rules involved. In a future post I’ll dive into the implications of value-type semantics for arrays. This post refers to reference and value types a lot. If you need a refresher on what that means, start with Values and References in VBA. Assignment rules You cannot assign TO fixed-length arrays, EVER I’ll start with the simplest rule: The VBA compiler does not allow
…read more

Values and References in VBA

April 25, 2013 in VBA

Visual Basic for Applications has a unique system of data types. One of the most fundamentally important concepts to understand is the difference between values and references in VBA, but it is very difficult to find clear explanations of this concept. I attempt to present one here. In this article I describe the difference between values and references, and between value types and reference types. In another article I will describe how the ByRef and ByVal keywords work. Synonyms When trying to make sense of this article in comparison with other articles and documentation, keep in mind that other sources
…read more

The Bang! (Exclamation Operator) in VBA

April 11, 2013 in VBA

One of the most peculiar aspects of Visual Basic for Applications in the ! operator, called the “bang”. It is particularly common in code for Microsoft Access, where you may see things like this: strCriteria = “EmployeeID = ” & Me!txtEmplID Set rst = CurrentDb.OpenRecordSet(“SELECT * FROM Employees WHERE ” & strCriteria) If Not rst.EOF Then Me!txtName = rst!Name Me!txtTitle = rst!Title Me!txtHireDate = rst!HireDate End If rst.Close Set rst = Nothing There’s a lot of confusion about the bang operator, and nowhere have I seen the correct whole story about it. So, I present it here! Definition: The Bang
…read more

Arrays in VBA – Part 1: Types of Arrays

March 29, 2013 in VBA

There are many kinds of arrays in Visual Basic for Applications. Specifically, there are three fundamental attributes of each array, determined at compile time by how the array is declared: Element data type Number of dimensions Fixed or Dynamic Length Each of these attributes will be discussed in detail in this article. Element data type Just as scalar (non-array) variables have a data type, arrays have a data type that restricts what can go in the elements of the array. As we will see in a later post all about array assignments, the declared data type of an array is
…read more

Collections in VBA – Overview

March 27, 2013 in VBA

In VBA programming collections of all types are indispensable. For both the new and experienced VBA programmer there is a lot to know about collection types in VBA, so I’m going to cover them one by one. In this post I’ll provide a quick survey of the available collection types. Types of Collections in VBA There are three fundamental collection types in VBA Array Collection Dictionary Arrays are a language feature and use value-type semantics (they do not use the Set keyword for assignments, for example). Collections and Dictionaries are object types provided by the Visual Basic for Applications library
…read more

Accurate Performance Timers in VBA

March 8, 2013 in VBA

There are many times when you want to know how fast your code really is. Especially if you find your VBA application responding slowly you need to know where the bottleneck is occurring. You can build a Stopwatch type class around the built-in VBA Timer function, but this will only get you resolution up to a few milliseconds and also suffers from some quirks in the Timer function. I won’t cover those in this article, but I will show how to make a super accurate Stopwatch class using the Windows API functions QueryPerformanceFrequency and QueryPerformanceCounter. For an in-depth look at
…read more

Copy and Paste in VBA

March 4, 2013 in VBA

It can be really handy to have simple string Copy and Paste functions in VBA. I use them frequently, as during development on MS Access applications I often use the Immediate window almost like an interactive command prompt. Sometimes I want to copy the output of a function directly to the clipboard, or fetch (Paste) data from the clipboard as input to a function. Using Microsoft Forms DataObject The most common way to implement Copy and Paste is to add a reference to Microsoft Forms 2.0 and use the DataObject class. Microsoft Forms often does not show up in the
…read more

Organizing Code With Namespaces in VBA

February 19, 2013 in VBA

Many programming languages provide ways of logically grouping code by name at multiple hierarchy levels, called namespaces. Java, JavaScript, ActionScript and others call them packages, and they are tied to the file system organization of the source code. .NET programming languages just call them namespaces and they can be defined anywhere independent of file structure. Identifiers in VBA Visual Basic for Applications does not provide a mechanism for this. Reflecting its origins more in procedural than object-oriented programming, all entity definitions in VBA exist in the global scope. In practical terms: Any function or sub defined in a standard module
…read more

Increasing Performance of Regular Expressions in VBA

February 12, 2013 in VBA

In a previous post I presented some general-purpose wrappers for adding regular expressions functionality to VBA and SQL in Microsoft Access. These wrappers work well, but we can make them much more efficient for situations where the same pattern is used many times, such as in a SQL query where the regular expression will be executed on each row of the input table or query. Caching Compiled Regular Expressions What we’ll use is the fact that, behind the scenes, every regular expression pattern gets compiled into a tiny little program that executes in order to actually apply the regular expression.
…read more