|
'导出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 |
|