Conditional SubReports - Case statement to print one of two subreports?

  • Thread starter cw via AccessMonster.com
  • Start date
C

cw via AccessMonster.com

I have a Report that has the following SubReports in the Detail section:

- subrptTelephoneService
- subrptMobilePhoneService

- subrptTelephoneTerms
- subrptMobilePhoneTerms

(each SubReport is based on it's own Table/Query)

How do I add a Case statement to do the following:
------------------------------------------------------------------------

SELECT CASE of subrptTelephoneService and subrptMobilePhoneService
If there is a TelephoneService, then print the TelephoneTerms
or
If there is a MobilePhoneService, then print the MobileTerms
Else
Do Not Print the Terms

-------------------------------------------------------------------------

Currently, If the Service SubReports have DATA, then they show up on the
report, but if NO DATA, then they do not. (Can Grow, Can Shrink is YES) and
both sets of Terms always print no matter what..

Thanks,
cw
 
D

Duane Hookom

I would try add code in the On Format event of the section of the report
containing the subreports:

Me.subrptTelephoneTerms.Visible = Me.subrptTelephoneService.HasData
Me.subrptMobilePhoneTerms.Visible = Me.subrptMobilePhoneService.HasData
 
C

cw via AccessMonster.com

Duane, Thanks for the reply.

I added that code to the On Format and get the Method or DataMember not found.
(The .HasData is not available in the Intellisense dropdown) Do I need to
switch these around..?

(All of my naming is correct)

Duane said:
I would try add code in the On Format event of the section of the report
containing the subreports:

Me.subrptTelephoneTerms.Visible = Me.subrptTelephoneService.HasData
Me.subrptMobilePhoneTerms.Visible = Me.subrptMobilePhoneService.HasData
I have a Report that has the following SubReports in the Detail section:
[quoted text clipped - 24 lines]
Thanks,
cw
 
D

Duane Hookom

My bad, try add "Report." prior to the HasData:

Me.subrptTelephoneTerms.Visible = Me.subrptTelephoneService.Report.HasData
Me.subrptMobilePhoneTerms.Visible = Me.subrptMobilePhoneService.Report.HasData
--
Duane Hookom
Microsoft Access MVP


cw via AccessMonster.com said:
Duane, Thanks for the reply.

I added that code to the On Format and get the Method or DataMember not found.
(The .HasData is not available in the Intellisense dropdown) Do I need to
switch these around..?

(All of my naming is correct)

Duane said:
I would try add code in the On Format event of the section of the report
containing the subreports:

Me.subrptTelephoneTerms.Visible = Me.subrptTelephoneService.HasData
Me.subrptMobilePhoneTerms.Visible = Me.subrptMobilePhoneService.HasData
I have a Report that has the following SubReports in the Detail section:
[quoted text clipped - 24 lines]
Thanks,
cw
 
C

cw via AccessMonster.com

Duane, Getting closer but..

Run-Time error 2467: The expression you entered refers to an object that is
closed or doesn't exist.

Do I need to create a SELECT CASE statement?
If so, how do I handle both scenarios..? sinc I need to Select the Case of
two Services?

Duane said:
My bad, try add "Report." prior to the HasData:

Me.subrptTelephoneTerms.Visible = Me.subrptTelephoneService.Report.HasData
Me.subrptMobilePhoneTerms.Visible = Me.subrptMobilePhoneService.Report.HasData
Duane, Thanks for the reply.
[quoted text clipped - 15 lines]
 
D

Duane Hookom

What is your final code and where are you running it from?
--
Duane Hookom
Microsoft Access MVP


cw via AccessMonster.com said:
Duane, Getting closer but..

Run-Time error 2467: The expression you entered refers to an object that is
closed or doesn't exist.

Do I need to create a SELECT CASE statement?
If so, how do I handle both scenarios..? sinc I need to Select the Case of
two Services?

Duane said:
My bad, try add "Report." prior to the HasData:

Me.subrptTelephoneTerms.Visible = Me.subrptTelephoneService.Report.HasData
Me.subrptMobilePhoneTerms.Visible = Me.subrptMobilePhoneService.Report.HasData
Duane, Thanks for the reply.
[quoted text clipped - 15 lines]
Thanks,
cw
 
C

cw via AccessMonster.com

My current code is as follows:
'-------------------------------------------
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
SigPlus2.ClearTablet
SigPlus2.DisplayPenWidth = 12
SigPlus2.JustifyMode = 5
SigPlus2.JustifyX = 10
SigPlus2.JustifyY = 10
SigPlus2.EncryptionMode = 0
SigPlus2.SigCompressionMode = 1
SigPlus2.SigString = Signature.Text

Me.subrptTermsConditions.Visible = Me.sfrmMainTeleServices4rpts.Report.
HasData
Me.subrptTermsConditionsMobile.Visible = Me.sfrmqryMobilePhoneService.
Report.HasData
End Sub
'-----------------------------------------

The names of my SubForms are correct (I originally posted sample names)
The SigPlus stuff is for printing the Digital Signature on the Report.
When I run the report the code stops on the first Me.subrpt section, and the
Error is on the right side of the = sign when I hover my mouse over the last
part.



Duane said:
What is your final code and where are you running it from?
Duane, Getting closer but..
[quoted text clipped - 14 lines]
 
D

Duane Hookom

Are you actually using subforms as subreports on a main report? If so, I
would convert the subforms to reports and use them. Make sure the expression
to the right of the "=" references the name of the subreport control in the
main report.
--
Duane Hookom
Microsoft Access MVP


cw via AccessMonster.com said:
My current code is as follows:
'-------------------------------------------
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
SigPlus2.ClearTablet
SigPlus2.DisplayPenWidth = 12
SigPlus2.JustifyMode = 5
SigPlus2.JustifyX = 10
SigPlus2.JustifyY = 10
SigPlus2.EncryptionMode = 0
SigPlus2.SigCompressionMode = 1
SigPlus2.SigString = Signature.Text

Me.subrptTermsConditions.Visible = Me.sfrmMainTeleServices4rpts.Report.
HasData
Me.subrptTermsConditionsMobile.Visible = Me.sfrmqryMobilePhoneService.
Report.HasData
End Sub
'-----------------------------------------

The names of my SubForms are correct (I originally posted sample names)
The SigPlus stuff is for printing the Digital Signature on the Report.
When I run the report the code stops on the first Me.subrpt section, and the
Error is on the right side of the = sign when I hover my mouse over the last
part.



Duane said:
What is your final code and where are you running it from?
Duane, Getting closer but..
[quoted text clipped - 14 lines]
Thanks,
cw
 
C

cw via AccessMonster.com

Duane, I think your onto something here:

When I look at the properties for one of my SubForms I have the following:
----------------------------
Name: sfrmqryMobilePhoneService
Visible: Yes
Source Object: Form.sfrmqryMobilePhoneService4rpts
Link Master Fields: ID
Link Child Fields: MPDetailID
---------------------------

Is there anyway to use your code without having to convert the SubForms to
SubReports..?


Duane said:
Are you actually using subforms as subreports on a main report? If so, I
would convert the subforms to reports and use them. Make sure the expression
to the right of the "=" references the name of the subreport control in the
main report.
My current code is as follows:
'-------------------------------------------
[quoted text clipped - 27 lines]
 
D

Duane Hookom

I don't print forms or subforms but you could try the following but I am a
bit pessimistic since I don't believe a subform has a HasData property. I
would save the subforms as reports and not compromise my standards ;-)

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
'....
Me.subrptTermsConditions.Visible = Me.sfrmMainTeleServices4rpts.Form.
HasData
Me.subrptTermsConditionsMobile.Visible = Me.sfrmqryMobilePhoneService.
form.HasData
End Sub

--
Duane Hookom
Microsoft Access MVP


cw via AccessMonster.com said:
Duane, I think your onto something here:

When I look at the properties for one of my SubForms I have the following:
----------------------------
Name: sfrmqryMobilePhoneService
Visible: Yes
Source Object: Form.sfrmqryMobilePhoneService4rpts
Link Master Fields: ID
Link Child Fields: MPDetailID
---------------------------

Is there anyway to use your code without having to convert the SubForms to
SubReports..?


Duane said:
Are you actually using subforms as subreports on a main report? If so, I
would convert the subforms to reports and use them. Make sure the expression
to the right of the "=" references the name of the subreport control in the
main report.
My current code is as follows:
'-------------------------------------------
[quoted text clipped - 27 lines]
Thanks,
cw
 
C

cw via AccessMonster.com

Duane, Do you know if there is any quick way to convert the subforms to
subreports?

Duane said:
I don't print forms or subforms but you could try the following but I am a
bit pessimistic since I don't believe a subform has a HasData property. I
would save the subforms as reports and not compromise my standards ;-)

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
'....
Me.subrptTermsConditions.Visible = Me.sfrmMainTeleServices4rpts.Form.
HasData
Me.subrptTermsConditionsMobile.Visible = Me.sfrmqryMobilePhoneService.
form.HasData
End Sub
Duane, I think your onto something here:
[quoted text clipped - 19 lines]
 
D

Duane Hookom

It doesn't get much easier than opening the form in design view and select
File->Save As and choosing report.
--
Duane Hookom
Microsoft Access MVP


cw via AccessMonster.com said:
Duane, Do you know if there is any quick way to convert the subforms to
subreports?

Duane said:
I don't print forms or subforms but you could try the following but I am a
bit pessimistic since I don't believe a subform has a HasData property. I
would save the subforms as reports and not compromise my standards ;-)

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
'....
Me.subrptTermsConditions.Visible = Me.sfrmMainTeleServices4rpts.Form.
HasData
Me.subrptTermsConditionsMobile.Visible = Me.sfrmqryMobilePhoneService.
form.HasData
End Sub
Duane, I think your onto something here:
[quoted text clipped - 19 lines]
Thanks,
cw
 
C

cw via AccessMonster.com

Duane, Your excellent reputation is still intact!
This works now that I have saved the SubForms as SubReports.
(I forgot about the Save As option) Thanks!

I actually have a total of 5 SubReports that I will try to use your code
logic on.
Thanks again,
cw


Duane said:
It doesn't get much easier than opening the form in design view and select
File->Save As and choosing report.
Duane, Do you know if there is any quick way to convert the subforms to
subreports?
[quoted text clipped - 16 lines]
 

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