VB6使用SQL查找问题(MS Access 2007)

时间:2011-04-06 09:14:16

标签: vb6

我有一个程序可以从数据库中找到记录(MS Access 2007),我发现错误:查询表达式中的语法错误'firstname like%1%'

这是我的代码:

 Dim find As String

 find = txtfind.Text

 If txtfind.Text <> "" Then
    Set rs = db.OpenRecordset("SELECT * from records WHERE firstname like '*'" & find & "'*")

    If rs.EOF = True Then
        MsgBox "No Record Found!", vbCritical + vbOKOnly, "Error"
    Else
        Text1 = rs(0)
        Text2 = rs(1)
        Text3 = rs(2)
        Text4 = rs(3)
    End If

    If Not rs Is Nothing Then
       Set rs = Nothing
    Else
       rs.Close
    End If

End If

1 个答案:

答案 0 :(得分:0)

Access的通配符是*不是%。

请尝试以下操作:

Set rs = db.OpenRecordset("SELECT * from records WHERE firstname like '*" & find & "*'")

此外,在访问中使用通配符的综合资源:

10 tips for using wildcard characters in Microsoft Access

希望有所帮助!