MS Access 2003 使用 SoundEx 从表单中搜索

发布于 2024-11-04 04:20:31 字数 945 浏览 0 评论 0原文

当按姓氏搜索时,我需要进行搜索以在数据库中查找“模糊匹配”。我已经实现了以下函数来启用 SoundEx 功能,没有任何问题。

在构建 SQL 来搜索动态调用 SoundEx 函数的数据库时,我遇到了问题。我知道VBA函数可以在SQL语句中调用,但它似乎不能正常工作。

Private Sub cmdSearch_Click()

Dim LSQL  As String
Dim LSearchString As String

If Len(txtSearchString) = 0 Or IsNull(txtSearchString) = True Then
    MsgBox "You must enter a search string."

Else
    LSearchString = txtSearchString
    LSQL = "SELECT * FROM TVictim "
    LSQL = LSQL & "WHERE Soundex([Victim Surname]) = " & Soundex(LSearchString) & ";"

    frmVictim.Form.RecordSource = LSQL


    lblTitle.Caption = "Matching Victim Details:  Filtered by '" & LSearchString & "'"
    txtSearchString = ""

    MsgBox "Results have been filtered.  All Victim Names containing " & LSearchString & "."

End If End Sub

当我在表单上输入字符串并单击按钮时,我已经单步执行了,在构建 SQL 时,它会弹出一个命令窗口,其中搜索框中包含文本的 SoundEx 输出,以及另一个数据框入口。

摆弄这个有一段时间了,似乎找不到有帮助的例子。

I need to get a search to look for "fuzzy matches" in a database when searching by Surname. I have implemented the following function to enable a SoundEx function, which has no issues.

I am getting issues when it comes to building the SQL to search through the database calling the SoundEx function on the fly. I know that VBA functions can be called in SQL statements, yet it doesn't seem to be working properly.

Private Sub cmdSearch_Click()

Dim LSQL  As String
Dim LSearchString As String

If Len(txtSearchString) = 0 Or IsNull(txtSearchString) = True Then
    MsgBox "You must enter a search string."

Else
    LSearchString = txtSearchString
    LSQL = "SELECT * FROM TVictim "
    LSQL = LSQL & "WHERE Soundex([Victim Surname]) = " & Soundex(LSearchString) & ";"

    frmVictim.Form.RecordSource = LSQL


    lblTitle.Caption = "Matching Victim Details:  Filtered by '" & LSearchString & "'"
    txtSearchString = ""

    MsgBox "Results have been filtered.  All Victim Names containing " & LSearchString & "."

End If End Sub

When I enter a string on the form and click the button, I have stepped through, and at the point it builds the SQL, its throws up a command window with the SoundEx output of the text in the search box, and another box for data entry.

Been fiddling with this for a while and can't seem to find an example that helps.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凯凯我们等你回来 2024-11-11 04:20:31

我在 Access 2003 中使用 Allen Browne 的 Soundex 函数: Soundex - 模糊匹配

它返回 Soundex 值作为字符串。如果您使用的 Soundex 函数也返回字符串,请用引号将 Soundex(LSearchString) 括起来,以便数据库引擎将其识别为字符串值,而不是缺少参数的名称。

LSQL = LSQL & "WHERE Soundex([Victim Surname]) = '" & Soundex(LSearchString) & "';"

I'm using Allen Browne's Soundex function with Access 2003: Soundex - Fuzzy matches

It returns the Soundex value as a string. If the Soundex function you're using also returns a string, enclose Soundex(LSearchString) with quotes so the database engine recognizes it as a string value instead of the name of a missing parameter.

LSQL = LSQL & "WHERE Soundex([Victim Surname]) = '" & Soundex(LSearchString) & "';"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文