Specifying the String-Comparison Setting for a Module

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

The Option Compare statement determines how strings are compared within a module. There are three settings for the Option Compare statement:

  • Option Compare Binary Strng comparisons are case-sensitive. Option Compare Binary is the default string-comparison setting for all the Microsoft® Office applications except Microsoft® Access, for which Option Compare Database is the default.

  • Option Compare Text Strng comparisons are case-insensitive. To make case-insensitive string comparison the default method for a module, add this statement to the module's Declarations section.

  • Option Compare Database Strng comparisons depend on the sort order for the specified locale; the default sort order is case-insensitive. The Option Compare Database setting is available only for Access databases. Note that when you create a new module in Access, the Option Compare Database statement is automatically inserted in the module's Declarations section. If you delete the Option Compare Database statement, the default string-comparison setting for the module is Option Compare Binary.

    **Note   **If you're writing code in Access that you might want to export to another Microsoft® Visual Basic® for Applications (VBA) host application, you should explicitly specify string comparisons as binary or text-based in the line that performs the comparison. Because the Option Compare Database setting is available only in Access, the code will not compile when you import it into another application unless you remove this setting. If you have explicitly specified the string-comparison method for each line that performs comparisons, you can export the code and be confident that string comparisons will continue to work as expected after you remove the Option Compare Database setting.

    Tip   To change the sort order for a database, click Options on the Tools menu, click the General tab, and then change the New Database Sort Order setting. After you change this setting, any new database you create will perform text comparisons based on the new sort order; changing this option has no effect on existing databases.

See Also

Getting the Most Out of Visual Basic for Applications | Comparing Strings | Comparing Strings by Using Comparison Operators | Overriding the Default String-Comparison Setting