Access数据库使用非重音search文本查找重音(Unicode)logging

我有一个MS Access数据库表,由德国客户的logging组成。 我在MS Excel中有一个用户表单,在其中input要search的名称。 提交表单后,它将在VBA中创build一个search查询,build立与数据库的连接并运行查询:

SELECT CustomerNumber FROM CustomerTable WHERE (CustomerName LIKE '%loffel%'); 

问题是,这个客户在数据库中被logging为“Löffel”。 当我search“loffel”时,它不会返回任何结果。

有没有办法使用Unicode字符search,仍然可以find结果?

这是您可能考虑的解决方法。 这不是很漂亮,但它似乎工作。

这个想法是让用户input一个没有重音字符的search词,并且VBA代码将用一个可能的变体列表replace指定的非重音字母,例如o被replace为[oö] ,所以

 ... LIKE '%loffel%' 

 ... LIKE '%l[oö]ffel%' 

使用这样的代码:

 Option Explicit Sub so38010103() Dim oChars As String ' eg, U+00F6 is "Latin Small Letter O With Diaeresis" oChars = "[o" & ChrW(&HF6) & "]" ' (add other accented "o"s above, and other character lists below, as needed) 'test data Const searchFor = "loffel" Dim conn As New ADODB.Connection conn.Open _ "DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};" & _ "DBQ=C:\Users\Public\so38010103.accdb" Dim cmd As New ADODB.Command cmd.ActiveConnection = conn cmd.CommandType = adCmdText cmd.CommandText = "SELECT COUNT(*) AS n FROM CustomerTable WHERE (CustomerName LIKE ?)" cmd.Parameters.Append cmd.CreateParameter("?", adVarWChar, adParamInput, 255) Dim rst As ADODB.Recordset ' test 1: literal search cmd.Parameters(0).Value = "%" & searchFor & "%" Set rst = cmd.Execute Debug.Print rst(0).Value & " record(s) found" ' 0 record(s) found rst.Close ' test 2: replace "o" with list of accented variants cmd.Parameters(0).Value = "%" & Replace(searchFor, "o", oChars, 1, -1, vbTextCompare) & "%" Set rst = cmd.Execute Debug.Print rst(0).Value & " record(s) found" ' 1 record(s) found rst.Close conn.Close End Sub