日期:2014-05-16  浏览次数:21173 次

access vba之子窗体数据筛选
Private Sub query_btn_Click()
  querycondition = querycon()
  queryresult.Form.FilterOn = False
  queryresult.Requery
  If Trim(querycondition) <> "" Then
    queryresult.Form.Filter = querycondition
    queryresult.Form.FilterOn = True
  End If
End Sub

?其中querycon用于生成查询(筛选)条件,并返回

?queryresult.Form.FilterOn表示筛选器的开关

?queryresult.Form.Filter表示筛选器的条件

?

querycon的大致语句如下:

 strcondition = ""
  If Trim(序号) <> "" Then
     If Trim(strcondition) <> "" Then
        strcondition = strcondition & " and "
     End If
     strcondition = strcondition & "序号=" & 序号
  End If
  If Trim(名称) <> "" Then
     If Trim(strcondition) <> "" Then
        strcondition = strcondition & " and "
     End If
     strcondition = strcondition & "名称 like '*" & 名称 & "*'"
  End If
  If Trim(代码) <> "" Then
     If Trim(strcondition) <> "" Then
        strcondition = strcondition & " and "
     End If
     strcondition = strcondition & "代码 ='" & 管理代码 & "'"
  End If
  If Trim(科室名称) <> "" Then
        If Trim(strcondition) <> "" Then
        strcondition = strcondition & " and "
     End If
     strcondition = strcondition & "科室名称 like '*" & 科室名称 & "*'"
  End If
  If Trim(姓名) <> "" Then
     If Trim(strcondition) <> "" Then
        strcondition = strcondition & " and "
     End If
     strcondition = strcondition & "姓名 like  '*" & 姓名 & "*'"
  End If
   If Trim(地址) <> "" Then
     If Trim(strcondition) <> "" Then
        strcondition = strcondition & " and "
     End If
     strcondition = strcondition & "地址 like '*" & 地址 & "*'"
  End If
  querycon = strcondition

?

?

?

根据以上代码?可制作以下窗体,实现access的多参数查询



?

?

?