|
本帖最后由 鱼儿游游 于 2012-8-6 18:20 编辑
以下代码已测试通过,供楼主参考。- Private Sub Command21_Click()
- Dim strSQL As String
- Dim intYear As Integer
- Dim intMonth As Integer
- '年、月
- intYear = Val(Trim(Nz(Me.Combo13.Column(0), "")))
- intMonth = Val(Trim(Nz(Me.Combo19.Value, "")))
- '生成SQL语句
- strSQL = "SELECT * FROM 表1"
- strSQL = strSQL & " WHERE 供应商 like '*" & Trim(Nz(Me.Combo0.Value, "")) & "*' "
- If intYear > 0 Then strSQL = strSQL & " AND Val(DatePart('yyyy',[日期]))=" & intYear
- If intMonth > 0 Then strSQL = strSQL & " AND Val(DatePart('m',[日期]))=" & intMonth
- '设置子窗体“表1 子窗体”的数据源
- Me.Controls("表1 子窗体").Form.RecordSource = strSQL
- Me.Controls("表1 子窗体").Form.Requery
- End Sub
复制代码 |
|