473,394 Members | 1,946 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Problem referring to SubReports

PhilOfWalton
1,430 Expert 1GB
I am using the following code to get the TAG information from forms, subforms, reports & subreports.

Expand|Select|Wrap|Line Numbers
  1. Function LoadFormOrReportLabels(FormOrReport As Integer, MainFormOrReportName As String, SubFormOrReportName As String)
  2. 'Debug.Print LoadFormOrReportLabels(1, 1, "FrmMsgBox", "FrmMsgBox")
  3.  
  4.     Dim TypeOfObject As Object
  5.  
  6.     On Error GoTo LoadFormOrReportLabels_Err
  7.  
  8.     If FormOrReport = 1 Then                                ' Forms
  9.         If MainFormOrReportName = SubFormOrReportName Then
  10.             Set TypeOfObject = Forms(MainFormOrReportName)
  11.         Else
  12.             Set TypeOfObject = Forms(MainFormOrReportName)
  13.             Set TypeOfObject = TypeOfObject.Controls(SubFormOrReportName).Form
  14.             If IsNull(TypeOfObject.Tag) Then
  15.                 TypeOfObject.Tag = TypeOfObject.Parent.Tag
  16.             End If
  17.         End If
  18.     ElseIf FormOrReport = 2 Then                            ' Reports
  19.         If MainFormOrReportName = SubFormOrReportName Then
  20.             Set TypeOfObject = Reports(MainFormOrReportName)
  21.         Else
  22.             Set TypeOfObject = Reports(MainFormOrReportName)
  23.             Set TypeOfObject = TypeOfObject.Controls(SubFormOrReportName).Report
  24.             If IsNull(TypeOfObject.Tag) Then
  25.                 TypeOfObject.Tag = TypeOfObject.Parent.Tag
  26.             End If
  27.         End If
  28.     End If
  29.  
FormOrReport = 1 for Forms & 2 for Reports and I pass the names of the main form or Report & the Subform or Report.

Surprisingly the line
Set TypeOfObject = TypeOfObject.Controls(SubFormOrReportName).Form
works perfectly for forms, but
Set TypeOfObject = TypeOfObject.Controls(SubFormOrReportName).Report
fails for subreports giving error 2455 You entered an expression that has an invalid reference to the property Form/Report.

Apart from the TAG property, I later need to refer to all the controls on the subreport, but my guess is that if I can get to the Tag, I can get to the controls.

Appreciate any advice

Phil
Jan 5 '18 #1
5 2148
NeoPa
32,556 Expert Mod 16PB
Here's some advice Phil - Name your objects carefully. TypeOfObject doesn't imply it's an object. It actually implies it isn't. Not helpful when working on code.

As for the Subform/Subreport object - Check whether it's using the Form property instead of the Report. Both exist so it would surprise me, but if I read your code correctly (in spite of the strange naming) then what you're doing should be fine.

That said, have you traced what's happening when the code runs?

Where is the function called from? At what stage in the process? It could be that it's running before the Subform/Subreport's Report object has been properly set.
Jan 7 '18 #2
PhilOfWalton
1,430 Expert 1GB
Thanks for reply. Your point about TypeOfObject is spot on and now changed to Obj.

Basically I call a Function
Function DbT_LoadLabels(MeName As String) As Boolean on opening both forms and reports.

This passes either
LoadFormOrReportLabels 1, MeName, MeName for forms or LoadFormOrReportLabels 2, MeName, MeName for reports to the function in my first post.

That function translates all the controls from one language to the required language. In the case of a SUBFORM, I just re-run the function and it works correctly translating the controls in the subform.

I had assumed that SUBREPORTS worked in the same way as Subforms in that they are opened before the main report opens, but have not been able to verify this.

The error 2455 You entered an expression that has an invalid reference to the property Form/Report seems to imply that the subreport is not open.

So I suppose the basic question is when do SubReports get opened? Does it depend on in which section of the main report the SubReport lies?

Thanks as ever,

Phil
Jan 7 '18 #3
NeoPa
32,556 Expert Mod 16PB
I don't have the SP on that Phil. I suggest you work with what you have and do some tests to see what's ready when. You may also find info in the Help system if you're lucky. I don't have such a system to play with. I have Subforms but no Subreports.
Jan 7 '18 #4
PhilOfWalton
1,430 Expert 1GB
Solved!!!!.

I moved the DbT_LoadLabels Me.Name from the OnOpen to the OnLoad Event of the main Report, and it works a treat.

Presumably the SubReports are opened after the OnOpen of the Report, but before the OnLoad

Useful gem for further reference.

Thanks again,

Phil
Jan 7 '18 #5
NeoPa
32,556 Expert Mod 16PB
Happy I could point you towards the answer Phil :-)
Jan 8 '18 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: David B | last post by:
I have a report with 2 sub reports on it. The report is an invoice and the sub reports are dropping data onto the invoice. This worked fine if generating 1 invoice at a time. I am trying to create...
1
by: Anne | last post by:
I have a report containing multiple subreports (approximately 37 subreports) that are based on individual queries. The query calls to only display the subreport if there is valid data in the table...
1
by: Don Sealer | last post by:
I have a report that includes 5 different subreports. I'd like to be able to open this report using a date function (Start Date and End Date). I'd like all five subreports to show the data from...
1
by: bobwooderton | last post by:
Either I am using the wrong approach or I just don't get it. so, the 'this' in 'this.changeState()' on the second to last line of the constructor code refers to the object _referObject, instead of...
3
by: Wayne | last post by:
I have a report containing 2 subreports. The subreports each contain a chart. The whole thing easily fits on one page but a second blank page is consistently being generated. This has nothing...
3
by: DeanL | last post by:
Hi all, I'm currently pulling out my already thin hair and need a little help if possible. I have an Access 97 db that is used to store inspection information for different regions. My report...
6
by: Brett Barry: Go Get Geek! | last post by:
Hello, I have a main report with a Record Source, a DateToday table, that has the current Month and Year. I have about 60 queries, each pulling different data via ODBC, that I am creating...
27
TheSmileyCoder
by: TheSmileyCoder | last post by:
Hi all my favorite Access elves, and happy NewYear. Im trying to modify a tabledef by code, and I seem to be running into some trouble. I am still in the early phases of getting an understanding...
1
by: Tim4692 | last post by:
I'm trying to create a main report (A) that creates a printout of all notes supervisors made for a single employee. There are five main categories of notes: Productivity, Professionalism,...
3
by: mcupito | last post by:
I am trying to pull the SUM() from 2 subreports. It works for one subreport, however not for the other. What I tried: I Sum() the field in the subreports, so I can refer to that field on the main...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.