Private Sub btnClear_Click()
Dim intIndex As Integer
' Clear all search items
Me.txtNodeName = ""
Me.txtE1 = ""
Me.txtSlot = ""
Me.txtDestination = ""
Me.txtCustomer = ""
Me.txtSO = ""
Me.cmbBitRate = 0
Me.cmbNetwork = 0
Me.cmbStatus = 0
End Sub
Private Sub Form_Load()
' Clear the search form
btnClear_Click
End Sub
Private Sub btnSearch_Click()
' Update the record source
Me.subfrmSearch.Form.RecordSource = "SELECT * FROM qryEquipment " & BuildFilter
' Requery the subform
Me.subfrmSearch.Requery
End Sub
Private Function BuildFilter() As Variant
Dim varWhere As Variant
Dim varItem As Variant
Dim intIndex As Integer
varWhere = Null ' Main filter
If Me.txtNodeName > "" Then
varWhere = varWhere & "[NodeName] LIKE """ & Me.txtNodeName & "*"" AND "
End If
If Me.txtE1 > "" Then
varWhere = varWhere & "[E1] LIKE """ & Me.txtE1 & "*"" AND "
End If
If Me.txtSlot > "" Then
varWhere = varWhere & "[Slot] LIKE """ & Me.txtSlot & "*"" AND "
End If
If Me.txtDestination > "" Then
varWhere = varWhere & "[Destination] LIKE """ & Me.txtDestination & "*"" AND "
End If
If Me.txtCustomer > "" Then
varWhere = varWhere & "[Customer] LIKE """ & Me.txtCustomer & "*"" AND "
End If
If Me.txtSO > "" Then
varWhere = varWhere & "[ServiceOrder] LIKE """ & Me.txtSO & "*"" AND "
End If
If Me.cmbBitRate > 0 Then
varWhere = varWhere & "[BitRate] = " & Me.cmbBitRate & " AND "
End If
If Me.cmbNetwork > 0 Then
varWhere = varWhere & "[Network] = " & Me.cmbNetwork & " AND "
End If
If Me.cmbStatus > 0 Then
varWhere = varWhere & "[Status] = " & Me.cmbStatus & " AND "
End If
If IsNull(varWhere) Then
varWhere = ""
Else
varWhere = "WHERE " & varWhere
If Right(varWhere, 5) = " AND " Then
varWhere = Left(varWhere, Len(varWhere) - 5)
End If
End If
BuildFilter = varWhere
End Function
Code (VB.NET)
[vb] If Me.txtNodeName > "" Then
varWhere = varWhere & "[NodeName] LIKE """ & Me.txtNodeName & "*"" AND "
End If
[vb]ต้องแก้ไขโค้ดอย่างไรบ้างคะ ? ขอบคุณค่ะ ..