Private Sub 查询_Click()
On Error GoTo Err_cmd查询_Click
Dim strWhere As String '定义条件字符串
Dim strOrderby As String '定义条件字符串
strWhere = "" '设定初始值-空字符串
If Trim(Me.日期) <> "" Then
'有输入
strWhere = strWhere & "([日期] like '*" & Me.日期 & "*')"
End If
If Trim(Me.文件id) <> "" Then
'有输入
strWhere = strWhere & IIf(strWhere <> "", " and ", "") & " ([文件id] like '*" & Me.文件id & "*')"
End If
Debug.Print strWhere '先在立即窗口显示一下strWhere的值,代码调试完成后可以取消下一句
'让子窗体应用窗体查询
Me.[专项和追加台账明细查询子窗体].Form.Filter = strWhere
Me.[专项和追加台账明细查询子窗体].Form.FilterOn = True
MsgBox Me.[专项和追加台账明细查询子窗体].Form.Filter
Me.[专项和追加台账明细查询子窗体].Form.OrderBy = strOrderby
Me.[专项和追加台账明细查询子窗体].Form.OrderByOn = True
Exit_cmd查询_Click:
Exit Sub
Err_cmd查询_Click:
MsgBox Err.Description
Resume Exit_cmd查询_Click
End Sub