Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Macros / November 2004

Tip: Looking for answers? Try searching our database.

Loop through query records

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
judith - 25 Nov 2004 09:01 GMT
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
Ken Snell [MVP] - 25 Nov 2004 17:00 GMT
Does the query name actually contain [ and ] characters? You do not need
those characters to delimit the name of a query in this step when the query
name has blank spaces in the name. Try this:

Set qdf = dbs.QueryDefs("mailingReportBase")

Signature

       Ken Snell
<MS ACCESS MVP>

> 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
[quoted text clipped - 19 lines]
>   DoCmd.OutputTo acReport, DLookup("[name]", "templates", _
>       "[templeId]=" &

[Forms]![systemForm]![mailContractForm].[Form]![letterFormBase].[Form]![temp
late]), _
>                 "RichTextFormat(*.rtf)", "C:\Documents and
> Settings\Judith\Desktop\test1\'" & [fileLoc] & "'.rtf", False
[quoted text clipped - 11 lines]
> Set rst = qdf.OpenRecordset()
> Too few parameters expected. Any suggestions please
judith - 26 Nov 2004 06:35 GMT
I think I have found my mistake from your great mvps.org/access site. The
query had a criteria based on an open form field. I now understand that it
must be a straight query so I will test for the criteria in the Do Loop.
Thanks very much for your help

> Does the query name actually contain [ and ] characters? You do not need
> those characters to delimit the name of a query in this step when the query
[quoted text clipped - 44 lines]
> > Set rst = qdf.OpenRecordset()
> > Too few parameters expected. Any suggestions please
Ken Snell [MVP] - 26 Nov 2004 16:09 GMT
That was going to be my next question... :-)

Glad it's working for you!

Signature

       Ken Snell
<MS ACCESS MVP>

> I think I have found my mistake from your great mvps.org/access site. The
> query had a criteria based on an open form field. I now understand that it
[quoted text clipped - 31 lines]
> > >   DoCmd.OutputTo acReport, DLookup("[name]", "templates", _
> > >       "[templeId]=" &

[Forms]![systemForm]![mailContractForm].[Form]![letterFormBase].[Form]![temp
> > late]), _
> > >                 "RichTextFormat(*.rtf)", "C:\Documents and
[quoted text clipped - 12 lines]
> > > Set rst = qdf.OpenRecordset()
> > > Too few parameters expected. Any suggestions please
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.