By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,122 Members | 921 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,122 IT Pros & Developers. It's quick & easy.

Problem referring to SubReports

Expert 100+
P: 1,430
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")
  4.     Dim TypeOfObject As Object
  6.     On Error GoTo LoadFormOrReportLabels_Err
  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
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

Jan 5 '18 #1
Share this Question
Share on Google+
5 Replies

Expert Mod 15k+
P: 31,419
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

Expert 100+
P: 1,430
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,

Jan 7 '18 #3

Expert Mod 15k+
P: 31,419
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

Expert 100+
P: 1,430

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,

Jan 7 '18 #5

Expert Mod 15k+
P: 31,419
Happy I could point you towards the answer Phil :-)
Jan 8 '18 #6

Post your reply

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