UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Omit Subreport If There Are No Pictures To Display., Access 2016    
 
   
dhapp
post Sep 10 2019, 10:01 AM
Post#1



Posts: 1,152
Joined: 17-November 03
From: Hamburg, NY


I have a report with a subreport. The subreport contains a Header with one Label and the Detail contains four picture locations.
This code, located in the OnOpen event of the subreport, determines the pictures that are used.
CODE
Private Sub Report_Open(Cancel As Integer)
    Dim strPath As String
    Dim strImagePath As String
    Dim lProspectID As Long
    Dim lEstID As Long
    
    lEstID = Forms!frmEstTypeOfWork!EstimateID
    strPath = "K:\ProposalWriterPics\"
    
    strImagePath = strPath & lEstID & "_Est1" & ".jpg"
    If FileExists(strImagePath) Then
        Me.Est1Img.Picture = strImagePath
    Else
        Me.Est1Img.Picture = ""
    End If
    
    strImagePath = strPath & lEstID & "_Est2" & ".jpg"
    If FileExists(strImagePath) Then
        Me.Est2Img.Picture = strImagePath
    Else
        Me.Est2Img.Picture = ""
    End If
    
    strImagePath = strPath & lEstID & "_Est3" & ".jpg"
    If FileExists(strImagePath) Then
        Me.Est3Img.Picture = strImagePath
    Else
        Me.Est3Img.Picture = ""
    End If
    
    strImagePath = strPath & lEstID & "_Est4" & ".jpg"
    If FileExists(strImagePath) Then
        Me.Est4Img.Picture = strImagePath
    Else
        Me.Est4Img.Picture = ""
    End If
End Sub
This works fine if there is one or more images.
I would like the subreport to not be included in the report if there are no picures to be displayed.

Do I need to create the conditional for the inclusion of the subreport prior to the subreport being opened, or can I cancel the opening of the subreport if there are no pictures to display?

--------------------
Doug
When the eagle is away, the crow says, "I am the eagle."
Go to the top of the page
 
dhapp
post Sep 10 2019, 10:31 AM
Post#2



Posts: 1,152
Joined: 17-November 03
From: Hamburg, NY


I figured it out.
I put a boolean function into the OnFormat event of the Detail section the main report.
CODE
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    Me.srptIllustrations.Visible = fnPicsToShow(Me.EstimateID)
End Sub

CODE
Public Function fnPicsToShow(lEstID As Long) As Boolean
    Dim strPath As String
    Dim strImagePath As String
    Dim iPic As Integer
    
    strPath = "K:\ProposalWriterPics\"
    
    strImagePath = strPath & lEstID & "_Est1" & ".jpg"
    If FileExists(strImagePath) Then
        iPic = iPic + 1
    End If
    
    strImagePath = strPath & lEstID & "_Est2" & ".jpg"
    If FileExists(strImagePath) Then
        iPic = iPic + 1
    End If
    
    strImagePath = strPath & lEstID & "_Est3" & ".jpg"
    If FileExists(strImagePath) Then
        iPic = iPic + 1
    End If
    
    strImagePath = strPath & lEstID & "_Est4" & ".jpg"
    If FileExists(strImagePath) Then
        iPic = iPic + 1
    End If
    
    fnPicsToShow = iPic > 0
End Function

--------------------
Doug
When the eagle is away, the crow says, "I am the eagle."
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    21st October 2019 - 05:48 AM