'选定你所要选定的区域,筛选代码你可以参照老六的窗口列子的筛选代码
Dim Filter As String
With e.Form.Controls("TextBox1")
If .Value IsNot Nothing Then
Filter = "车辆基本情况_车牌号码 = '" & .Value & "'"
End If
End With
With e.Form.Controls("ComboBox1")
If .Value IsNot Nothing Then
If Filter > "" Then
Filter = Filter & " And "
End If
Filter = Filter & "车辆基本情况_车牌颜色 = '" & .Value & "'"
End If
End With
With e.Form.Controls("ComboBox2")
If .Value IsNot Nothing Then
Filter = "处理环节 = '" & .Value & "'"
End If
End With
With e.Form.Controls("ComboBox3")
If .Value IsNot Nothing Then
Filter = "处罚情况_案件状态 = '" & .Value & "'"
End If
End With
With e.Form.Controls("ComboBox4")
If .Value IsNot Nothing Then
Filter = "处理方式 = '" & .Value & "'"
End If
End With
With e.Form.Controls("DateTimePicker1")
If .Value IsNot Nothing Then
If Filter >"" Then
Filter = Filter & " And "
End If
Filter = Filter & "违章基本情况_违章时间 >= #" & .Value & "#"
End If
End With
With e.Form.Controls("DateTimePicker2")
If .Value IsNot Nothing Then
If Filter >"" Then
Filter = Filter & " And "
End If
Filter = Filter & "违章基本情况_违章时间 <= #" & .Value & "#"
End If
End With
'筛选后全部选定区域
With Tables("车辆违章表")
.Select(0,0, .Rows.Count - 1, .Cols.Count - 1)
End With
'打印代码
Dim Book As New XLS.Book(ProjectPath & "Attachments\违章车辆统计报表.xls") '打开模板
Dim Sheet As XLS.Sheet = Book.Sheets(0)
Book.Build() '生成细节区
Book.Save("D:\release\reports\违章车辆统计报表.xls") '保存工作簿
Dim App As New MSExcel.Application
Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open("D:\release\reports\违章车辆统计报表.xls")
Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
App.Visible = True
Ws.PrintPreview
'Ws.PrintOut
App.Quit