referencing subreport items

G

gtslabs

I am trying to reference fields [expr1] on a subreport to compare it
to a textbox [CFStartDate] on the main report so I can conditional
format it. I want to do this with VBA not the built in Conditional
Formating.

I am geting invalid reference errors.
What is the correct format to compare the 2 items?

'If Reports!rptSampleSet!subrptBreaks!Expr1 >= CFStartDate Then
MsgBox "YES" 'Just for testing
End If

I tried with brackets [] and still could not get it to work.


Also
Is there a way to see the full path length of an object? So if I click
on the [expr1] in the subreport it will show its complete name
including the parent form? I know the Properties window shows it
local name.
Thanks
 
T

tina

well, you didn't say whether you're running the code from within the
mainreport or the subreport. if in the mainreport, try

Me!subrptBreaks.Report!Expr1 >= Me!CFStartDate

make sure that the name of the subreport control (that's the control within
the main report that "holds" the subreport object) is subrptBreaks. if it's
not, change the above line of code to use the name of the subreport control.

if in the subreport, try

Me!Expr1 >= Me.Parent!CFStartDate

hth
 
G

gtslabs

well, you didn't say whether you're running the code from within the
mainreport or the subreport. if in the mainreport, try

    Me!subrptBreaks.Report!Expr1 >= Me!CFStartDate

make sure that the name of the subreport control (that's the control within
the main report that "holds" the subreport object) is subrptBreaks. if it's
not, change the above line of code to use the name of the subreport control.

if in the subreport, try

    Me!Expr1 >= Me.Parent!CFStartDate

hth




I am trying to reference fields [expr1] on a subreport to compare it
to a textbox [CFStartDate] on the main report so I can conditional
format it.  I want to do this with VBA not the built in Conditional
Formating.
I am geting invalid reference errors.
What is the correct format to compare the 2 items?
'If Reports!rptSampleSet!subrptBreaks!Expr1 >= CFStartDate Then
MsgBox "YES"  'Just for testing
End If
I tried with brackets [] and still could not get it to work.
Also
Is there a way to see the full path length of an object? So if I click
on the [expr1] in the subreport it will show its complete name
including the parent form?  I know the Properties window shows it
local name.
Thanks- Hide quoted text -

- Show quoted text -

Well I got part of it to work.
I am opening up a report based on a query in a form.
So I guess that code is not in either the report or subreport.

From my Form Listbox:
Private Sub LboxProjectSummary_DblClick(Cancel As Integer)
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

DoCmd.OpenReport "rptSampleSet", acViewPreview, , "pROJECT = '" &
Me.LboxProjectSummary & "'"
MsgBox Me.cboStartDate ' This works
MsgBox Me!subrptBreaksColumns.Report!Expr1 'This does not

End Sub


So the Me.cboStartDate worked
But the Me!subrptBreaksColumns.Report!Expr1 did not work.

I assume I need to put any conditional formating code in a program
that runs once the report is open and not from the calling code?
Because I can not see those fields as called in my code above.

I have 2 fields in the main report (rptSampleSet) called CFStartDate
and CFEndDate
I have 3 fields in a subreport (subrptBreaksColumns) called Expr1,
Expr5, Cycle. (Expr1 is a Date)
I was trying to see if Expr1 is between those start and end dates and
if so highlight all 3 fields in the subreport.
 
T

tina

okay, you're running the code from the *form*. that makes a big difference.
try

With Reports("ReportName")
!subrptBreaksColumns.Report!Expr1 >= !CFStartDate
End With

if this is a single-record report, "conditional formatting" from outside the
report should work okay. but if it's a multi-record report, you may need to
use the Conditional Formatting option in the subreport. and i'm not sure how
well it will work, frankly. in a *form*, the subform opens BEFORE the
mainform; if that order is the same for a subreport/mainreport, the
mainreport value may not yet be availabe to the conditional expression when
it runs to format the subreport.

btw, you said
I was trying to see if Expr1 is between those start and end dates

what start and end dates are you referring to? the expression you posted
compares the subreport date to only a single date on the mainreport, as
"greater than or equal to" which is not the same as "Between date1 and
date2".

hth


well, you didn't say whether you're running the code from within the
mainreport or the subreport. if in the mainreport, try

Me!subrptBreaks.Report!Expr1 >= Me!CFStartDate

make sure that the name of the subreport control (that's the control within
the main report that "holds" the subreport object) is subrptBreaks. if it's
not, change the above line of code to use the name of the subreport control.

if in the subreport, try

Me!Expr1 >= Me.Parent!CFStartDate

hth




I am trying to reference fields [expr1] on a subreport to compare it
to a textbox [CFStartDate] on the main report so I can conditional
format it. I want to do this with VBA not the built in Conditional
Formating.
I am geting invalid reference errors.
What is the correct format to compare the 2 items?
'If Reports!rptSampleSet!subrptBreaks!Expr1 >= CFStartDate Then
MsgBox "YES" 'Just for testing
End If
I tried with brackets [] and still could not get it to work.
Also
Is there a way to see the full path length of an object? So if I click
on the [expr1] in the subreport it will show its complete name
including the parent form? I know the Properties window shows it
local name.
Thanks- Hide quoted text -

- Show quoted text -

Well I got part of it to work.
I am opening up a report based on a query in a form.
So I guess that code is not in either the report or subreport.

From my Form Listbox:
Private Sub LboxProjectSummary_DblClick(Cancel As Integer)
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

DoCmd.OpenReport "rptSampleSet", acViewPreview, , "pROJECT = '" &
Me.LboxProjectSummary & "'"
MsgBox Me.cboStartDate ' This works
MsgBox Me!subrptBreaksColumns.Report!Expr1 'This does not

End Sub


So the Me.cboStartDate worked
But the Me!subrptBreaksColumns.Report!Expr1 did not work.

I assume I need to put any conditional formating code in a program
that runs once the report is open and not from the calling code?
Because I can not see those fields as called in my code above.

I have 2 fields in the main report (rptSampleSet) called CFStartDate
and CFEndDate
I have 3 fields in a subreport (subrptBreaksColumns) called Expr1,
Expr5, Cycle. (Expr1 is a Date)
I was trying to see if Expr1 is between those start and end dates and
if so highlight all 3 fields in the subreport.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top