J
judith
I am trying to loop through records in a query and save a report to word for
each record. Steve Schapel kindly got me started with some code but I am a
bit stuck
So far
Private Sub Command1_Click()
Dim dbs As Database
Dim rst As DAO.Recordset
Dim qdf As DAO.QueryDef
Dim BaseSQL As String
Set dbs = CurrentDb
Set qdf = dbs.QueryDefs("[mailingReportBase]")
Set rst = qdf.OpenRecordset()
BaseSQL = qdf.SQL
Do Until rst.EOF
qdf.SQL = Left(BaseSQL, Len(BaseSQL) - 3) & " WHERE [companyId] =" &
rst![companyId]
DoCmd.OutputTo acReport, DLookup("[name]", "templates", _
"[templeId]=" &
[Forms]![systemForm]![mailContractForm].[Form]![letterFormBase].[Form]![template]), _
"RichTextFormat(*.rtf)", "C:\Documents and
Settings\Judith\Desktop\test1\'" & [fileLoc] & "'.rtf", False
Loop
rst.Close
Set rst = Nothing
qdf.SQL = BaseSQL
Set qdf = Nothing
Set dbs = Nothing
End Sub
I get an error on
Set rst = qdf.OpenRecordset()
Too few parameters expected. Any suggestions please
each record. Steve Schapel kindly got me started with some code but I am a
bit stuck
So far
Private Sub Command1_Click()
Dim dbs As Database
Dim rst As DAO.Recordset
Dim qdf As DAO.QueryDef
Dim BaseSQL As String
Set dbs = CurrentDb
Set qdf = dbs.QueryDefs("[mailingReportBase]")
Set rst = qdf.OpenRecordset()
BaseSQL = qdf.SQL
Do Until rst.EOF
qdf.SQL = Left(BaseSQL, Len(BaseSQL) - 3) & " WHERE [companyId] =" &
rst![companyId]
DoCmd.OutputTo acReport, DLookup("[name]", "templates", _
"[templeId]=" &
[Forms]![systemForm]![mailContractForm].[Form]![letterFormBase].[Form]![template]), _
"RichTextFormat(*.rtf)", "C:\Documents and
Settings\Judith\Desktop\test1\'" & [fileLoc] & "'.rtf", False
Loop
rst.Close
Set rst = Nothing
qdf.SQL = BaseSQL
Set qdf = Nothing
Set dbs = Nothing
End Sub
I get an error on
Set rst = qdf.OpenRecordset()
Too few parameters expected. Any suggestions please