Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA: Change a subreport control's caption using indirect method

Status
Not open for further replies.

aldi07

MIS
Jun 22, 2010
100
CA
Hi,
The question applies to Ms-Access 2003:
To change the caption on a subform's control using the indirect method, I do:
<<Forms(MyForm)(MySubForm)(MyControl).Caption = MyTable(MyControl)>>
where MyTable contains different captions. It works very well.
For reports, the following works well:
<<Reports(MyReport)(MyControl).Caption = MyTable(Mycontrol)>>
But for subreports, it does not work: When I do:
<<Reports(MyReport)(MySubReport)(MyControl).Caption = MyTable(Mycontrol)>>
I get the error message:
"Microsoft Office Access can't find the field 'MySubReport' referred to in your expression"
For some reason, it considers 'MySubReport' as a field instead of a subreport...
Any ideas anyone?
Thank you.
 
I do:
<<Forms(MyForm)(MySubForm)(MyControl).Caption = MyTable(MyControl)>>
I doubt you do that, because that does not work. You have to reference the form/report object within the subform/subreport control

forms("myForm").mySubForm.Form.mycontrol
reports(myreport).mySubreport.report.mycontrol
 
Hi MajP,
Thank you for your answer. However it does work, for forms as well as reports. I needed it "indirect" because I use it as a function for many forms and subforms, reports and subreports, to choose the language to display in labels.
Attached is a very simplistic example, using no tables, just to show how to use the syntax for these indirect caption VBA settings.
In my example, open the form, and try the different buttons, you will see that it works well. For the report and subreport, after choosing a language in the form, click on report, and the on-open event will do the trick.
You can see all the codes attached to form, subform, report, and subreport.
Basically:
For forms: Forms(MyForm)(MyControl).Caption = "etc..."
For SubForms: Forms(MyForm)(MySubform)(MyControl).Caption = "etc..."
For Reports: Reports(MyReport)(MyControl).Caption = "etc..."
For SubReports: Reports(MyReport)(MySubReport)(MyControl).Caption = "etc..."
Where: MyForm = "frmFormHeader"
MySubForm = "frmSubFormDetail"
MyReport = "rptReportHeader"
MySubReport = "rptSubReportDetail"
and MyControl = "Label01"
Hope it helps whoever needs such a feature.
Regards.
 
It seems my attahment didn't go through. I changed the name to test. Hope it will work. It is on my desk top.
 
Doesn't work either. I moved it to C:\Test.mdb
 
Sorry for all the replies, I can't seem to attach my database here. It is in C:\Test.mdb
Can anybody tell me how to attach the document?
Thank you.
 
you can use a file sharing site like 4shared.com
 
Your code might work, but what you show will not work. Assuming the indices are passed as strings.
This would work
Forms(MyForm)(MySubform).form(MyControl).Caption
But not as you say
Forms(MyForm)(MySubform)(MyControl).Caption
 
How are ya aldi07 . . .

To make your db available upload it to an online storage site. The site will provide and address for download that you can use. Try 4Shared ... [blue]its free![/blue] [thumbsup2]



See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Hi TheAceMan1,
Thank you for your reply. I used MediaFire that is recommended by this very Tek-Tips Forum. Did you have any difficulty downloading it?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top