opening report from form with variable recordsource

P

phleduc

I am opening a report from a form in designview while changing the
recordsource. (see code below)
This works well, the report opens with the appropriate data source
but when I am closing the report wiht the "close" button (print preview
toolbar), it opens in design view.
This does not happen when I close the report with the "close window" x on
the right side of the menu bar?
Anybody an idea how to make it work from the close button as well?

Me.application.Echo False
Dim stDocName As String
stDocName = "Rpt1010_FinancialOverviewByMonth_Graph"
DoCmd.OpenReport stDocName, acViewDesign
Reports!Rpt1010_FinancialOverviewByMonth_Graph!Graph1.RowSource =
"SELECT * from Qry1010_ExpensesGraph WHERE [periodval] >= " &
Me.cboGraphStart & " and [periodval] <= " & Me.cboGraphEnd
DoCmd.Save ( OR I tried DoCmd.Save acReport,
"Rpt1010_FinancialOverviewByMonth_Graph")
DoCmd.OpenReport stDocName, acPreview
Me.application.Echo True
(I also tried to save after going to preview, no difference)
 
D

Duane Hookom

I would probably set the graph Row Source to a saved query and use code to
change the SQL property of the query.

Dim strSQL as String
strSQL ="SELECT * from Qry1010_ExpensesGraph " & _
"WHERE [periodval] >= " & Me.cboGraphStart & " and [periodval] <= " &
Me.cboGraphEnd & ";"
CurrentDb.QueryDefs("qselForGraph").SQL = strSQL
DoCmd.OpenReport ....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top