|
石三少同志的问题:子窗体筛选后导出任意字段内容到EXCEL中,而不是整条记录导出,该如何写代码?
解答:
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
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|