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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to tell which Report is the parent of a subreport?

Status
Not open for further replies.

lorirobn

MIS
Mar 15, 2005
450
0
0
US
Hi -

Is there a way, in a subreport's vba code, to know which report is the 'parent'? I would like to use a subreport in several different reports, and would like format the background colors differently for one of the reports. How can I check which 'parent' called this subreport? Do I need to set up my own global variables for this?

Thanks in advance for any help,
Lori
 
You should be able to use code like the following in the On Format event of whatever section you want to change:

Code:
  Select Case Me.Parent.Name
     Case "rptEmployee"
        Me.Section(0).BackColor = vbYellow
     Case "rptPhoneList"
        '
     Case "rptDeptList"
        '
  End Select


Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Thanks, Duane.

On a similar note, in a Function I have created (it's a separate module), can I tell which report or program called it?

Thanks once again - you have helped me many times!

Lori
 
I don't believe you can identify where a function call came from without sending an argument or setting a global variable. With forms, you might be able to use something like:
Screen.ActiveForm
with reports, you may be SOL.



Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Hi Duane,

I am just now putting in the Me.Parent.Name into my subreport's code. I am getting an error: invalid reference to the Parent property. (and 'Name' didn't get capitalized, which was my first clue).

I've tried Me.Parent.Name, Report.Parent.Name, and several variations of this in my Detail_Format event of the subreport. I will now try using a global, but I was just curious about this statement.

Thanks,
Lori
 
Duane - Just got it to work, somehow. I sit scratching my head, wondering why it didn't work just a few minutes ago.
But anyway - thanks for the tips. Me.Parent.name works (even tho' name still isn't capitalized).

- Lori
 
Do you have any field named "name" in a record source?

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top