Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

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

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

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

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?

RE: Syntax for current subreport's subreport control on the parent?

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.

RE: Syntax for current subreport's subreport control on the parent?

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


Private Sub Report_Current()
  MsgBox GetSubFormControl(Me).Name
End Sub 

RE: Syntax for current subreport's subreport control on the parent?

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close