|
- Function 查询()
- Dim strWhere As String
- '如果姓名不为空,则将其加入到条件字符串
- If Not IsNull(Me.姓名) Then strWhere = strWhere & "姓名='" & Me.姓名 & "' AND "
- '如果性别不为空,则将其加入到条件字符串
- If Not IsNull(Me.性别) Then strWhere = strWhere & "性别='" & Me.性别 & "' AND "
- '如果籍贯不为空,则将其加入到条件字符串
- If Not IsNull(Me.籍贯) Then strWhere = strWhere & "籍贯='" & Me.籍贯 & "' AND "
- '这里为了判断简便,最前面必定会有一个“ AND ”,这是不需要的,这里去掉它
- 'strWhere = Mid(strWhere, 6)
- If Not IsNull(Me.time1) Then strWhere = strWhere & "([日期] >= #" & Format(Me.time1, "yyyy-mm-dd") & "#) AND "
- If Not IsNull(Me.time2) Then strWhere = strWhere & "([日期] <= #" & Format(Me.time2, "yyyy-mm-dd") & "#) AND "
- If Len(strWhere) <> 0 Then
- '有输入条件
- strWhere = Left(strWhere, Len(strWhere) - 5)
- End If
- '先在立即窗口显示一下strWhere的值,代码调试完成后可以取消下一句
- ' Debug.Print strWhere
- '设置子窗体的筛选器条件
- Me.frmChild.Form.Filter = strWhere
- '应用筛选
- Me.frmChild.Form.FilterOn = True
- End Function
复制代码 |
|