开发者

VB6 Find Problem using SQL(MS Access 2007)

I had a program that will find a record from a database(MS Access 2007) where im havin an error: Syntax Error in query expression 'firstname like %1%'

this is my code:

 Dim find As String

 find = txtfind.Text

 If txtfind.T开发者_如何学Pythonext <> "" 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


The Wildcard character for Access is * not %.

Please try with the following:

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

Also, a comprehensive resource for using wildcard characters in access:

10 tips for using wildcard characters in Microsoft Access

Hope that helps!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜