|
Function 导出数据(tbname As String, frmname As String, subfrmname As String, Qdefname As String, ParamArray A() As Variant)
'功能:导出子窗体数据到Excel中
'参数:tbname--子窗体数据表
' frmname--主窗体名称
' subfrmnane--子窗体名称
' Qdefname--查询名称
' A()--导出的字段数组
Dim Qdef As QueryDef
Dim strWhere, strSQL As String
Dim i As Long
strWhere = Forms(frmname).Controls(subfrmname).Form.Filter
If strWhere = "" Then strWhere = "True"
strSQL = ""
For i = 0 To UBound(A, 1)
strSQL = strSQL & A(i) & ","
Next
If strSQL = "" Then
strSQL = "*"
Else
strSQL = Left(strSQL, Len(strSQL) - 1)
End If
strSQL = "SELECT " & strSQL & " FROM " & tbname & " WHERE " & strWhere
If DCount("*", "MSysObjects", "Type=5 and Name='" & Qdefname & "'") = 0 Then
Set Qdef = CurrentDb.CreateQueryDef(Qdefname)
Qdef.SQL = strSQL
End If
Set Qdef = CurrentDb.QueryDefs(Qdefname)
Qdef.SQL = strSQL
Qdef.Close
Set Qdef = Nothing
DoCmd.OutputTo acOutputQuery, Qdefname, acFormatXLS, , True
End Function |
|