Microsoft Access - Explicitly Declare Variable Data Types (Access 97/2000/2002/2003)

When declaring variables, be sure to always explicitly specify the variable's data type. For instance, if you're declaring a variable to hold a text string, declare it as:

  • Dim strMyText As String

Instead of just:

  • Dim strMyText

If you don't specify the data type, the variable is declared as a Variant type. Not only does a Variant require more memory, but they're also slower to process and your code could produce errors or inappropriate results if any statements depend on data that's stored as a specific data type. Of course, there are times when a Variant is desirable. However, you should explicitly declare them as such for clarity (ex.: Dim varValue As Variant).

Go back