如何按类别搜索?

时间:2015-10-12 07:13:58

标签: search datagrid vb6

这又是我。 ^ _ ^ 我可以问一下如何按类别过滤特定记录?我只知道如何只过滤一个类别。这是我的代码。请帮我。谢谢!

If txtName.Text = "" Then
MsgBox "Please enter what you want to filter.", vbInformation, "Message Box"
txtName.SetFocus

Else
If Not myRS.EditMode And myRS.BOF = True Then
MsgBox "No record found!", vbCritical, "Search Result"

Else
myRS.Filter = "TL LIKE '" & txtName.Text & "*'"
Set DataGrid1.DataSource = myRS

DataGrid1.Columns(0).Caption = "Work Group"
DataGrid1.Columns(1).Caption = "Team Leader"
DataGrid1.Columns(2).Caption = "Dept Head"
DataGrid1.Columns(3).Caption = "Participants"
DataGrid1.Columns(4).Caption = "Date Created"
DataGrid1.Columns(5).Caption = "Coach"
DataGrid1.Columns(6).Caption = "Problem"
DataGrid1.Columns(7).Caption = "Measure Impacted"
DataGrid1.Columns(8).Caption = "Status"
DataGrid1.Columns(9).Caption = "Where"
DataGrid1.Columns(10).Caption = "When"
DataGrid1.Columns(11).Caption = "How Much/Many"
DataGrid1.Columns(12).Caption = "Who"

2 个答案:

答案 0 :(得分:0)

假设您填写myRS的查询类似于

Select WorkGroup, TL, DeptHead, ...., Category From blah blah

您可以将您的行更改为

myRS.Filter = "TL LIKE '" & txtName.Text & "*' OR Category LIKE '" & txtName.Text & "*'"

这将为您提供与txtName匹配的TL和类别,或者您可以创建除txtName之外的新文本框,可能是txtCategory,然后将行更改为

myRS.Filter = "TL LIKE '" & txtName.Text & "*' AND Category LIKE '" & txtCategory.Text & "*'"

答案 1 :(得分:0)

在表单中添加一个组合框。并填写

dim item 
Combo1.clear
For Each item In Array("Work Group", "Team Leader", "Dept Head" _
          , "Participants", "Date Created", "Coach"  _
          ,  "Problem", "Measure Impacted", "Status"  _
          , "Where", "When", "How Much/Many", "Who")

     Combo1.AddItem item
Next

然后:

i=combo1.listindex
if(i=-1) then 
   'ErrorMessageHere
    exit sub
end if
myRS.Filter = "[" & myRS.Fields(i).Name & "] LIKE '*" & txtName.Text & "*'"