ongke0711 > 20-01-17, 08:08 PM
Option Compare Database
Option Explicit
Function getStringFromComma(fld As String, strSearch As String) As String
Dim x As String, xArr() As String, strCriteria As String
Dim i As Byte
x = strSearch
If Len(x) > 0 Then
xArr = Split(x, ",")
For i = 0 To UBound(xArr)
If Len(xArr(i)) = 0 Then
'do nothing ->khong co tri, bo qua cac dau phay ma khong co chuoi tim kiem
Else
strCriteria = strCriteria & fld & " LIKE '*" & Trim(xArr(i)) & "*' OR "
End If
Next
getStringFromComma = Trim(Left(strCriteria, Len(strCriteria) - 4)) 'Bo chu OR cuoi chuoi
Else
getStringFromComma = fld & " LIKE '*'"
End If
End Function
Option Compare Database
Option Explicit
Private Sub cmdSearch_Click()
If IsNull(Me.txtSearchText) Or Me.txtSearchText = "" Then
MsgBox " Không có du lieu tìm kiem"
Exit Sub
End If
Dim strSQL As String
strSQL = "SELECT * FROM tblUserInfo WHERE " & getStringFromComma("username", Me.txtSearchText)
Me.sfmUsersList.Form.RecordSource = strSQL
Me.sfmUsersList.Requery
End Sub
Private Sub cmdShowAll_Click()
Dim strSQL As String
strSQL = "SELECT * FROM tblUserInfo"
Me.sfmUsersList.Form.RecordSource = strSQL
Me.sfmUsersList.Requery
End Sub
ckno1no > 23-01-17, 01:32 PM