• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 643
  • Last Modified:

Hide subreport if record is null, but display when not null

Looking for the best approach to hiding a subreport if for a record = null, else display the record.

I mean I want the titles hidden if the record = Null.

thanks,

karen
0
Karen Schaefer
Asked:
Karen Schaefer
2 Solutions
 
Rey Obrero (Capricorn1)Commented:
normally, a subreport will not show if there is no data to show

you can also check the subreport.hasdata  (true/False) property  on the No Data Event of your Main report

If [SubReportName1].HasData = 0 then
   ' what you need to do
end if
0
 
Karen SchaeferAuthor Commented:
will that work for each record on a continuous report?
0
 
Karen SchaeferAuthor Commented:
Private Sub Report_Current()
If [rptDBAQuestionsSub].HasData = 0 Then
    Me.lblOutQuestion.Visible = False
    Me.lblSuggestion.Visible = False
End If
End Sub


this is not working. where is the best place to place the code?

K
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Rey Obrero (Capricorn1)Commented:
what?
0
 
Rey Obrero (Capricorn1)Commented:
did you read my first post?
0
 
Karen SchaeferAuthor Commented:
ok I tried it on the no Data event still not return the results I am expecting.

Private Sub Report_NoData(Cancel As Integer)

If [rptDBAQuestionsSub].HasData = 0 Then
    Me.rptDBAQuestionsSub.Visible = False
    Me.lblOutQuestion.Visible = False
    Me.lblResponder.Visible = False
    Me.lblSuggestion.Visible = False
Else
    Me.rptDBAQuestionsSub.Visible = True
    Me.lblOutQuestion.Visible = True
    Me.lblResponder.Visible = True
    Me.lblSuggestion.Visible = True

End If
End Sub

Open in new window

0
 
Karen SchaeferAuthor Commented:
Screen shot of reportl

screen shot
Yellow illustrates where subreport should be hidden.

Thanks.
0
 
Karen SchaeferAuthor Commented:
Subreport w/data
0
 
Rey Obrero (Capricorn1)Commented:
need to see the report..
0
 
Karen SchaeferAuthor Commented:
pick this up in the a.m.  thanks for the input.  do you want the actual report or is the attached screen shot sufficient?

Thanks
0
 
GrahamMandenoCommented:
Hi Karen

I think you need to use the Format event of the (Detail?) section containing the subreport, nor the Current event.

Why don't you include the column header labels in the report header of the subreport?  That way, if there is no data and the subreport does not print, then you will not see the labels either.

Graham Mandeno [Access MVP 1996-2015]
0
 
Karen SchaeferAuthor Commented:
Graham,

Thanks for the suggestion, however, having issue with the criteria for the Detail_Format

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If [rptDBAQuestionsSub].HasData = 0 Then
    Me.rptDBAQuestionsSub.Visible = False
    Me.rptDBAQuestionsSub.CanShrink = True
'    Me.lblOutQuestion.Visible = False
'    Me.lblResponder.Visible = False
'    Me.lblSuggestion.Visible = False
'    Me.lblDateCreated.Visible = False
Else
    Me.rptDBAQuestionsSub.CanShrink = False
    Me.rptDBAQuestionsSub.Visible = True
'    Me.lblOutQuestion.Visible = True
'    Me.lblResponder.Visible = True
'    Me.lblSuggestion.Visible = True
'    Me.lblDateCreated.Visible = True
End If

If [rptUseCaseSub].HasData = 0 Then
    Me.rptUseCaseSub.CanShrink = False
Else
    Me.rptUseCaseSub.CanShrink = True
End If

End Sub
0
 
Karen SchaeferAuthor Commented:
It does not like the hasdata portion of the code.
0
 
Rey Obrero (Capricorn1)Commented:
you can only use the "hasdata" in the main report event i mentioned above.
0
 
Helen FeddemaCommented:
You could perhaps make the entire subreport control invisible if certain criteria are met.  But we really need to examine the report in a database to see what is going on.
0
 
Rey Obrero (Capricorn1)Commented:
<But we really need to examine the report in a database to see what is going on. > I already ask about that report... :-(
0
 
Karen SchaeferAuthor Commented:
thanks Graham & Rey.

I got it to work, thanks for the input


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

    If Reports![rptRequirementMain]![rptDBAQuestionsSub].Report.HasData = 0 Then
       
        Reports![rptRequirementMain]![rptDBAQuestionsSub].Report.Visible = False
    Else
        Reports![rptRequirementMain]![rptDBAQuestionsSub].Report.Visible = True
    End If
   
    If Reports![rptRequirementMain]![rptUseCaseSub].Report.HasData = 0 Then
        Reports![rptRequirementMain]![rptUseCaseSub].Report.Visible = False
    Else
        Reports![rptRequirementMain]![rptUseCaseSub].Report.Visible = True
    End If

    If Me.Duplicate_Req = True Or Me.Active = False Then
        Me.lblOpsolete.Visible = True
        Reports![rptRequirementMain]![rptUseCaseSub].Report.Visible = False
        Reports![rptRequirementMain]![rptDBAQuestionsSub].Report.Visible = False
    Else
        Me.lblOpsolete.Visible = False
        Reports![rptRequirementMain]![rptUseCaseSub].Report.Visible = True
        Reports![rptRequirementMain]![rptDBAQuestionsSub].Report.Visible = True
    End If
End Sub
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now