Access 2013 - Use attachment and show the content in a form (if pdf or jpg) RRS feed

  • Question

  • Hello,

    Once i have stored an attachment to an item of a table, is there a way to display the attachment if it is a pdf or a jpg in a form? (and eventually show a generic "format not compatible" message if it is none of the listed file type?


    Thanks all!

    Tuesday, January 17, 2017 8:05 AM

All replies

  • Hi,

    We could use an Attachment control in a form to show the image or icon. And then handle Form_Current event to check the format.

    The code below checks the attachment extension, if there is no .jpg or .pdf, the control is invisible.

    Private Sub Form_Current()
    Attach.Visible = False
    For i = 0 To Attach.AttachmentCount - 1
    If Right(Attach.OldValue(i), 3) = "jpg" Or Right(Attach.OldValue(i), 3) = "pdf" Then
    Attach.Visible = True
    End If
    Next i
    If Attach.Visible = False Then
    MsgBox "format not compatible"
    End If
    End Sub

    Using Attachment controls, we could see the picture, but for other files type, it shows as an icon.

    So if you want to show other file like pdf, you might use Web Browser control to show the attachment.

    But none of them could be changed into other control type like label to display the text "format not compatible", so I would suggest choose other ways to show the alert. For attachment controls, you may make it invisible or change its displayed type, see AcDisplayAs Enumeration.



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Chenchen Li Monday, January 23, 2017 10:24 AM
    Wednesday, January 18, 2017 5:36 AM