Question

Say there is a spreadsheet or table in MS access which contains non English characters (diacritics) such as à, á, â, ã, ä, å, æ, ç, è, é, ê, ë

Since this system is used by English speakers, the end-user, when searching for values cannot guess whether or not certain words or names were entered in the English version or in the original version.

That is, días might be originally entered into the databse as días or dias. coñac might be entered as coñac or conac. In fact sometimes data is entered this way and sometimes the other way.

The question is whether there is a way to set this search options, so built-in office search mechanism (Ctrl+f) would find días when dias is supplied.

If there is not, I would like to hear what would be your approach to solve this problem.

Was it helpful?

Solution

GUI search dialog's matching behavior in Office apps is not customizable. But if I were in your shoes, here's how I'd solve the problem:

First, you'll need some .NET code which performs accent-insensitive searches. Depending on which language you like best, here's both a VB and C# sample. The core of this is using the CompareInfo.IndexOf method using a CompareOptions parameter set to CompareOptions.IgnoreNonSpace. This is an accent-insensitive search.

Next, you'll need to call this code from the Office app. How you plug code in varies by app-- for example, here are blog posts showing how to do this from Excel and Access.

Then you'll need to wrap those calls around code and UI which simulates a search and replace. This again will be different in each app. For example, in Excel you'll loop through all cells in the current worksheet and look for matches using your code.

Finally, you'd want to map that code to a toolbar button or other way to get your code invoked.

Anyway, hope this is enough info to help you get started. Here's the core .NET code in either VB or C# to do accent-insensitive matches:

VB

Module Module1
    Sub Main()
        ' returns: 3
        Dim pos As Integer = FindIgnoreDiacritics("àcçëñt-énäblêd", "en")
    End Sub
    Function FindIgnoreDiacritics(ByVal lookIn As String, ByVal lookFor As String) As Integer
        FindIgnoreDiacritics = System.Globalization.CultureInfo.InvariantCulture.CompareInfo.IndexOf(lookIn, lookFor, System.Globalization.CompareOptions.IgnoreNonSpace Or System.Globalization.CompareOptions.IgnoreCase)
    End Function
End Module

C#

class Program
{
    static void Main(string[] args)
    {
        // returns: 3
        int pos = FindIgnoreDiacritics("àcçëñt-énäblêd", "en");
    }
    static int FindIgnoreDiacritics(string lookIn, string lookFor)
    {
        return System.Globalization.CultureInfo.InvariantCulture.CompareInfo.IndexOf(lookIn, lookFor,
            System.Globalization.CompareOptions.IgnoreNonSpace | System.Globalization.CompareOptions.IgnoreCase);
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top