I am trying to export a report over and over again with code. The report is based on a query that contains a parameter. I fill the parameter by scrolling through a recordset. The report is suppose to export itself after each record change. My problem is that my paremeter is not getting set for the report, I am getting the parameter dialog box when I try to export the first report. I think it may have something to do with the querydef not actually being the record source for my report since a querydef is just a copy of that query. But I don't know how to change my reports recordsource to the querydef in my code.
Sub ExportAuto()
Dim Db As DAO.Database
Dim Rst As DAO.Recordset
Dim Rst1 As DAO.Recordset
Dim qdf1 As DAO.QueryDef
Dim qdf2 As DAO.QueryDef
Dim Rpt As String
Dim FileLocation As String
Dim fundName As String
Set Db = CurrentDb()
Set qdf2 = Db.QueryDefs("qryFundsInDatabase"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
Set qdf1 = Db.QueryDefs("qryDifferencesSorted1"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
Set Rst = qdf2.OpenRecordset(dbOpenDynaset)
Rpt = "rptDifferencesSorted1"
FileLocation = "C:\My Documents\Work\"
With Rst
.MoveFirst
Do While Not Rst.EOF
fundName = Rst!Fund
qdf1.Parameters("EnterFund"
= fundName
DoCmd.OutputTo acOutputReport, Rpt, acFormatXLS, FileLocation & fundName & Rpt & ".xls"
.MoveNext
Loop
End With
MsgBox "Export complete", vbInformation
End Sub
Thanks in advance
Dan
Sub ExportAuto()
Dim Db As DAO.Database
Dim Rst As DAO.Recordset
Dim Rst1 As DAO.Recordset
Dim qdf1 As DAO.QueryDef
Dim qdf2 As DAO.QueryDef
Dim Rpt As String
Dim FileLocation As String
Dim fundName As String
Set Db = CurrentDb()
Set qdf2 = Db.QueryDefs("qryFundsInDatabase"
Set qdf1 = Db.QueryDefs("qryDifferencesSorted1"
Set Rst = qdf2.OpenRecordset(dbOpenDynaset)
Rpt = "rptDifferencesSorted1"
FileLocation = "C:\My Documents\Work\"
With Rst
.MoveFirst
Do While Not Rst.EOF
fundName = Rst!Fund
qdf1.Parameters("EnterFund"
DoCmd.OutputTo acOutputReport, Rpt, acFormatXLS, FileLocation & fundName & Rpt & ".xls"
.MoveNext
Loop
End With
MsgBox "Export complete", vbInformation
End Sub
Thanks in advance
Dan