|
本帖最后由 todaynew 于 2011-6-14 20:29 编辑
付谦 发表于 2011-6-12 21:07
我建立了一个查询,条件其姓名=子窗体中的姓名,然后导出成EXICL,结果只能导出一条记录,我想导出与子窗体中的 ...
1、写两个自定义函数如下:
Public Function AccToExl(frm As Form)
'示例:AccToExl(me.子窗体.form)
Dim ssql As String
Dim strwh As String
ssql = frm.RecordSource
ssql = Trim(ssql)
If Right(ssql, 1) = ";" Then
ssql = Left(ssql, Len(ssql) - 1)
End If
ssql = "select * from (" & ssql & ") where "
strwh = "True"
If frm.Filter <> "" Then
strwh = strwh & " and " & frm.Filter
End If
ssql = ssql & strwh
CrtQDef "TempQ", ssql
DoCmd.OutputTo acOutputQuery, "TempQ", acFormatXLS
DoCmd.DeleteObject acQuery, "TempQ"
End Function
Public Function CrtQDef(strname As String, strsql As String)
'创建查询
Dim Qdef As QueryDef
Set Qdef = CurrentDb.CreateQueryDef(strname)
Qdef.SQL = strsql
Qdef.Close
Set Qdef = Nothing
End Function
2、在主窗体的导入按钮单击事件中写:
call AccToExl(me.子窗体.form)
|
|