changing source object

G

Guest

I have created a main report with multiple possible subreports. I placed an
unbound subreport in the main form with ON OPEN code:
Private Sub Report_Open(Cancel As Integer)
dim strSUBREP as string

if [Forms]![FM_MAIN]![age] = "Yes" then
strSUBREP = "subreport1"
else
strSUBREP = "subreport2"
end if
Me.subreport = strSUBREP
exit sub

Am getting the error 2450: can't find 'FM_MAIN' refered to in a VB code.
FM_MAIN is the main form where the field age is located. I have tried using
Forms!FM_MAIN.age but still of no use. What should i do? Thanks in advance!
 
A

Allen Browne

Presumably fm_main is a form (not a report)?

Is the form open (not in design view) at the time?

Try changing the SourceObject property of the subreport control. That may
still not work, since Access opens the subreport *before* the main reports.
 
G

Guest

Thanks Allen!
FM_MAIN is a form and it was open (not in design view) when the preview icon
was clicked. The preview icon is located in FM_MAIN. What do you mean by
changing the Source Object property of the subreport control? I tried placing
and removing a source object, while the other property are more on the FORMAT.

Allen Browne said:
Presumably fm_main is a form (not a report)?

Is the form open (not in design view) at the time?

Try changing the SourceObject property of the subreport control. That may
still not work, since Access opens the subreport *before* the main reports.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

benj said:
I have created a main report with multiple possible subreports. I placed
an
unbound subreport in the main form with ON OPEN code:
Private Sub Report_Open(Cancel As Integer)
dim strSUBREP as string

if [Forms]![FM_MAIN]![age] = "Yes" then
strSUBREP = "subreport1"
else
strSUBREP = "subreport2"
end if
Me.subreport = strSUBREP
exit sub

Am getting the error 2450: can't find 'FM_MAIN' refered to in a VB code.
FM_MAIN is the main form where the field age is located. I have tried
using
Forms!FM_MAIN.age but still of no use. What should i do? Thanks in
advance!
 
A

Allen Browne

No, I don't think that will work.

Perhaps you could place the various subreports on the main report, and then
toggle their Visible property so as to show or hide them, e.g.:

If [Forms]![FM_MAIN]![age] = "Yes" Then
Me.[Sub1].Visible = True
Else
Me.[Sub1].Visible = False
End If

BTW, if age is a yes/no field, you will need:
If [Forms]![FM_MAIN]![age] = True Then

We don't know what you are aiming to do, so it's not clear if that's the
best approach, or whether you would be better to create different reports
and call them depending on the values in the form.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

benj said:
Thanks Allen!
FM_MAIN is a form and it was open (not in design view) when the preview
icon
was clicked. The preview icon is located in FM_MAIN. What do you mean by
changing the Source Object property of the subreport control? I tried
placing
and removing a source object, while the other property are more on the
FORMAT.

Allen Browne said:
Presumably fm_main is a form (not a report)?

Is the form open (not in design view) at the time?

Try changing the SourceObject property of the subreport control. That may
still not work, since Access opens the subreport *before* the main
reports.

benj said:
I have created a main report with multiple possible subreports. I
placed
an
unbound subreport in the main form with ON OPEN code:
Private Sub Report_Open(Cancel As Integer)
dim strSUBREP as string

if [Forms]![FM_MAIN]![age] = "Yes" then
strSUBREP = "subreport1"
else
strSUBREP = "subreport2"
end if
Me.subreport = strSUBREP
exit sub

Am getting the error 2450: can't find 'FM_MAIN' refered to in a VB
code.
FM_MAIN is the main form where the field age is located. I have tried
using
Forms!FM_MAIN.age but still of no use. What should i do? Thanks in
advance!
 

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