HasData Property

S

Scott

I have the below code in the detail format event in my report. It works
fine, evaluates if data exists in the subreport and hides/shows myTxtLabel
depending on the existance of subreport data.

However, if I change the name of the subreport to any other name, this code
gives an error "Access can't find the field 'myReportSub' referred to in
your expression."

I always open the report in design view and change the subreport's name
before trying to run it, but Access refuses to run my code with any changes
to the subreport.

Is there any other way to test if a subform contains data or doesn't? I just
need to show/hide a label when data exists or doesn't.


CODE *********


Private Sub Detail1_Format(Cancel As Integer, FormatCount As Integer)

Me.mytxtLabel.Visible = Reports![myReport]![myReportSub].Report.HasData
End Sub
 
D

Dirk Goldgar

Scott said:
I have the below code in the detail format event in my report. It
works fine, evaluates if data exists in the subreport and hides/shows
myTxtLabel depending on the existance of subreport data.

However, if I change the name of the subreport to any other name,
this code gives an error "Access can't find the field 'myReportSub'
referred to in your expression."

I always open the report in design view and change the subreport's
name before trying to run it, but Access refuses to run my code with
any changes to the subreport.

Is there any other way to test if a subform contains data or doesn't?
I just need to show/hide a label when data exists or doesn't.


CODE *********


Private Sub Detail1_Format(Cancel As Integer, FormatCount As Integer)

Me.mytxtLabel.Visible =
Reports![myReport]![myReportSub].Report.HasData End Sub

I don't understand. If you change the name of the subreport control,
why would you expect a reference to the old name to work? Why are you
changing the name of the subreport control every time you open the
report? Bear in mind that you can change the SourceObject property of
the subreport control, to point to a different report object, without
changing the name of the subreport control itself.
 
S

scott

i'm manually changing the subreport once, just for a better naming
convention.

Dirk Goldgar said:
Scott said:
I have the below code in the detail format event in my report. It
works fine, evaluates if data exists in the subreport and hides/shows
myTxtLabel depending on the existance of subreport data.

However, if I change the name of the subreport to any other name,
this code gives an error "Access can't find the field 'myReportSub'
referred to in your expression."

I always open the report in design view and change the subreport's
name before trying to run it, but Access refuses to run my code with
any changes to the subreport.

Is there any other way to test if a subform contains data or doesn't?
I just need to show/hide a label when data exists or doesn't.


CODE *********


Private Sub Detail1_Format(Cancel As Integer, FormatCount As Integer)

Me.mytxtLabel.Visible =
Reports![myReport]![myReportSub].Report.HasData End Sub

I don't understand. If you change the name of the subreport control,
why would you expect a reference to the old name to work? Why are you
changing the name of the subreport control every time you open the
report? Bear in mind that you can change the SourceObject property of
the subreport control, to point to a different report object, without
changing the name of the subreport control itself.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
D

Dirk Goldgar

scott said:
i'm manually changing the subreport once, just for a better naming
convention.

If you change the name of the subreport control that was originally
"myReportSub", you need to change that also in the code that refers to
it:

Reports![myReport]![myReportSub].Report.HasData

So if you renamed the subreport control to "SomeOtherSubreport", for
example, the code reference would change to:

Reports![myReport]![SomeOtherSubreport].Report.HasData

If you just change the subreport control's Source Object property,
though, to load some other subreport, then you don't need to change the
code.
 

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