subreport recordsource

S

Sherlin

i trying to set report recordsource base on user selection value but
encounter problem setting subreport recordsource.

1.
If str = 1 Then
Me.RecordSource = "Q1"
Me.subreportname.Report.RecordSource = "subQ1"
ElseIf str = 2 Then
Me.RecordSource = "Q2"
Me.subreportname.Report.RecordSource = "subQ2"

But, I getting run-time error '2455'
You entered an expression that has an invalid reference to the property
Form/Report.

Even i try another method, idea from another post in this discussion group
whereby set subreport recordsource in subreport report_open proc with below
code, but

2.
Static ini As Boolean

If Not ini Then
If GstrCntrLoadType = 1 Then
Me.RecordSource = "subQ1"

ElseIf GstrCntrLoadType = 2 Then
Me.RecordSource = "subQ2"
...
End If
ini = True
End If

Getting problem, subQ1 record is not display at all... I confirm subQ1
having data. Seems like the link of main report and subreport have been gone.

Could anyone highligh to me whats wrong with my code or any idea how to set
subreport recordsource?
 
K

Klatuu

You have encountered a weird attribute of Access. Sub forms and sub reports
actually load before the main form or main report. At the time your code
executes, the references to the main report have not yet been established.

You did not say in which event you have your code. I would suspect it is
the Open event. I can't be sure it will work, but you may try moving the
code to the report Activate event.
 

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