|
本帖最后由 liuqi67 于 2017-1-3 10:36 编辑
要求:依选项组按钮的查询条件导出对应子窗体上的查询内容到excel。
做了一个选项组按钮查询子窗体,需要按选项按钮执行的查询条件导出对应子窗体上的内容,菜鸟级水平,想了好些办法没搞定,导出的总是全部内容,无法实现按筛选的内容导出。
如下示例为选项组三个按钮的查询语句:
Private Sub Option23_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.产品分类统计_子窗体.Form.RecordSource = "select * from 产品分类统计查询 "
End Sub
Private Sub Option25_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.产品分类统计_子窗体.Form.RecordSource = "select * from 产品分类统计查询 where nz(Round([已提供]/[物料总数]*100,2),0)=100"
End Sub
Private Sub Option27_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.产品分类统计_子窗体.Form.RecordSource = "select * from 产品分类统计查询 where nz(Round([已提供]/[物料总数]*100,2),0)<100"
End Sub
如下示例为刘小军老师的导出代码,怎么将上面的变量写入到创建的查询中然后导出EXCEL?望高手指教,感谢!
Private Sub 导出_Click()
On Error GoTo Err_cmd导出_Click
Dim qdf As DAO.QueryDef 'qdf被定义为一个查询定义对象
Dim strWhere, strSQL As String
strWhere = 产品分类统计_子窗体.Form.Filter
If strWhere = "" Then
'没有条件
strSQL = "SELECT * FROM [产品分类统计查询]"
Else
'有条件
strSQL = "SELECT * FROM [产品分类统计查询] WHERE " & strWhere
End If
Set qdf = CurrentDb.QueryDefs("产品分类统计导出")
qdf.SQL = strSQL
qdf.Close
Set qdf = Nothing
DoCmd.OutputTo acOutputQuery, "产品分类统计导出", "Excel97-Excel2003Workbook(*.xls)", , True
Exit_cmd导出_Click:
Exit Sub
Err_cmd导出_Click:
MsgBox Err.Description, , "确定要取消保存吗?"
Resume Exit_cmd导出_Click
End Sub
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|