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!

Syntax for current subreport's subreport control on the parent? 1

Status
Not open for further replies.

lameid

Programmer
Jan 31, 2001
4,208
US
I have a main report that has literals in textboxes that are used as the Master Fields for subreports.

One subreport that can be repeated multiple times in the main report (and I don't mean because of data) formats itself based on a value/data. The report is being reused form another process which sets a the value consumed in the Detail sections format event, the problem is that the format event fires before data is loaded. I need to figure out a way to set this value and it would seem the easy way to get it would be from the control value on the main report specified for the subreport control's master field. This brings me to the subject question, what is the syntax for the current subreport's subreport control on the parent?

I am open to alternate solutions but would prefer not having to modify code to generate the multiple permutations of the sub report objects. A little more background, the main report and most other subreports are generated via code. The problem subreport is for a particularly cumbersome one-off. I still have to modify code to use the one off where appropriate.

I guess each subreport could be a copy of the report and embedded in the name is the needed value as Me.Name is available all the time. Can anyone save me from this option?
 
I went with the report value embedded in the name of the object idea....

The build process crashes every single time it reaches near the end and runs docmd.close and save all on the report. Export to PDF fails on bigger reports because a "custom macro is preventing the report..." so this idea was doomed from the start.

Using this report wasn't my idea in the first place. So on the pro list is vindication. However if I was using the value from the name for something simple I suspect it would work but I can't fathom a reason to do that is not also just as goofy as this. I yield. We'll just have to go with my plan A.
 
Code:
Public Function GetSubFormControl(subrpt As Access.Report) As SubForm
  Dim ctrl As Access.control
  For Each ctrl In subrpt.Parent.Controls
    If ctrl.ControlType = acSubform Then
      If ctrl.Report Is subrpt Then
        Set GetSubFormControl = ctrl
      End If
     End If
   Next ctrl
 End Function

This works for me
Test from the subform
Code:
Private Sub Report_Current()
  MsgBox GetSubFormControl(Me).Name
End Sub
 
That looks good for the OP question... I have so rarely used IS I forgot about it. Brilliant. I was thinking a similar loop based on the report name but obviously missing the mark with multiple instances.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top