DoCmd.OpenReport and RecordSource property

  • Thread starter Thread starter KK
  • Start date Start date
K

KK

Hi

I have a report template. The data is generated by a pretty
complex query in VBA. The problem I am having is when
I try to assign the query to the report.

If I try to open the report as below
DoCmd.OpenReport "Review_Form", etc...

I can't set its RecordeSource to the query I generated.

but if I use

Set rptLetters = CreateReport(, "rpt_To_Reviewer")
rptLetters.RecordSource = strSQLQuery
rptLetters.Caption = "Reviewer Letters"
etc...

it opens a blank report. not my template.

I first want to set the recordsource in the report and then
open it. how can I do it?

rgds
KK
 
Not sure what you mean by a "report template", but if you designed a report,
and assigned the record source in the properties section for the report to a
saved query called "strSQLQuery, then you wouldn't need any VBA coding.

Damon
 
Hi Larry

Nope, I think I am doing something unnecessary.
See, what I need is to pass some parameters to the SQL query

Now I know if i use access saved queries, for my query, it will
pop up msg boxes asking for teh parameters. I want to avoid this.
So my query is in VBA where I do some string manipulations and
create the final query with the parameters appended... so lets say I
come up with a string with a query like

select * from sometable where this=that and blah blah

now, i have a report which uses the fields I retrieve from the above query
problem is I can't assign the rowsource using the DoCmd.OpenReport isn't it?
 
Back
Top