2016-06-24 3 views
1

독일어 고객 레코드로 구성된 MS Access 데이터베이스 테이블이 있습니다. MS Excel에서 검색 할 이름을 입력하는 사용자 양식이 있습니다. 내가 양식을 제출 한 후에는, VBA에서 검색 쿼리를 만들고 데이터베이스에 대한 연결을 설정하고 쿼리를 실행합니다Access 데이터베이스 비 액센트 검색 텍스트를 사용하여 악센트 부호가있는 (유니 코드) 레코드 찾기

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

문제는,이 고객이 'Löffel'로 데이터베이스에 기록됩니다. 'loffel'을 검색하면 결과가 반환되지 않습니다.

유니 코드 문자로 검색하고 결과를 찾을 수있는 방법이 있습니까?

+0

'O' <>'O', 그 모든 인코딩과 문자 집합에 대한 사실 . 그래서 나는 생각한다. – Andre

+0

@Andre처럼 나는 그렇게 생각하지 않습니다. 그러한 문자를 대체 할 수 있습니까? '% l? ffel %' '로 표시됩니다. 물론 Lüffel, Léffel, Läffel도 일치 할 것이지만 아마도 0 번 경기보다 좋을 것입니다. – Gustav

답변

1

다음은 고려할 수있는 대안입니다. 그것은 예쁘지 않지만 작동하는 것 같습니다.

아이디어는 사용자가 악센트 부호가없는 검색어를 입력하게하고 VBA 코드는 지정된 악센트가없는 문자를 가능한 변형 목록으로 대체합니다 (예 : o가 너무

... LIKE '%loffel%' 

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

사용하여 코드를 다음과 같이되고, [oö]으로 대체됩니다 :

Option Explicit 

Sub so38010103() 
    Dim oChars As String 
    ' e.g., 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