Dim conn As New ADODB.Connection
connStr = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=C:\a.mdb"
conn.Open connStr
Dim rs As New ADODB.Recordset
sql = "select top 1 * from [user]"
rs.Open sql, conn, adOpenForwardOnly
FiledStr = ""
For Each Field In rs.FIElds ''生成每個字段的sql
If FIEld.Type = 202 Then ''文本型字段
If FiledStr = "" Then
FiledStr = FiledStr + FIEld.Name + " like ''%" + StrSearch + "%''"
Else
FiledStr = FiledStr + " or " + FIEld.Name + " like ''*" + StrSearch + "*''"
End If
End If
Next
rs.Close
sql = "select * from [user] where " + FiledStr ''查詢
rs.Open sql, conn, adOpenForwardOnly ''這就是結果了。
Do While Not rs.EOF
MsgBox (rs(0))
rs.MoveNext
Loop
rs.Close
conn.Close