我需要在VBA中使用MS-Access提供一些帮助。我没有太多的编码器,但能够在访问中编译成员资格数据库。无论如何,我的会员搜索遇到了问题:任何成员的名字在姓氏和名字字段中都包含“'”,如“O'Conner”,“O'Neil”等,无法找到搜索,而其他人的名字都很好。有人可以指出我正确的方向吗?这是代码:
Dim stDocName As String
stDocName = "MemberView"
Dim swhere As String
'Search by name
If Not IsNull(txtFullName) Then
Dim sFullName As String
Dim sLastName As String
Dim sFirstName As String
Dim icount As String
sFullName = txtFullName
sLastName = Left(sFullName, InStr(1, sFullName, ",") - 1)
sFirstName = LTrim(Mid(sFullName, InStr(1, sFullName, ",") + 1))
swhere = "[Last Name]='" & sLastName & "' and [First Name]='" & sFirstName & "'"
icount = DCount("[Last Name] and [First Name]", "Members", swhere)
If icount > 1 Then
MsgBox " " & icount & " found"
Else
End If
Else
End If
我希望这是一些简单的事情或者只是一些我设置错误的变量。
非常感谢!
答案 0 :(得分:1)
这是众所周知的问题。看看这里:http://allenbrowne.com/casu-17.html
尝试用双['
]替换单个[""
]并检查会发生什么。
swhere = "[Last Name]=""" & sLastName & """ and [First Name]=""" & sFirstName & """"