热度 1||
'导出Excel函数
'Qname--查询名称
'Pfrmane--父窗体名称
'Ctlname--子窗体控件名称
'n--n=1按子窗体,n=2按子窗体数据源查询
Public Function myoutE(Qname As String, Pfrmname As String, Ctlname As String, n As Long)
Dim myform As Form
Dim Qdef As QueryDef
Dim strSQL As String
Dim myformname As String
Set myform = Forms(Pfrmname).Controls(Ctlname).Form
myformname = myform.Name
SQLstr = myform.Form.RecordSource
SQLstr = "select * from " & SQLstr
Set Qdef = CurrentDb.QueryDefs(Qname)
Qdef.sql = SQLstr
Select Case n
Case 1
DoCmd.OutputTo acOutputForm, myformname, acFormatXLS, CurrentProject.Path & "导出表.xls", True
Case 2
DoCmd.OutputTo acOutputQuery, Qanme, acFormatXLS, CurrentProject.Path & "导出表.xls", True
End Select
Qdef.Close
Set Qdef = Nothing
End Function
|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )
GMT+8, 2024-5-13 06:48 , Processed in 0.061188 second(s), 17 queries .
Powered by Discuz! X3.3
© 2001-2017 Comsenz Inc.