Display multiple attachments in microsoft access 2010 forms and reports

半世苍凉 提交于 2019-11-29 07:58:54

Let us say I have a table with an attachment:

Let us say that I have three images in one of those attachment fields that I wish to display. I can create a query:

After which I can create a continuous form:

I searched this for a similar problem. I have multiple attachments per field. I intend to use the field to store a .jpg and a .pdf for two image controls which I created by dragging the field from the properties to the form. I have named them ctlImage and ctlFeatures. I am using this form as a non modal popup from a more info button on the product catalog form. So far I am able to search records in the product catalog and use the selected listbox search result to open the form with a where clause to set the details form to the current record. When I try to manipulate the ctlImage looking for image type the only property which shows in intellisense is ctlImage.value. I was hoping to assign ctlImage to jpg and ctlFeatures to pdf Here is the frmProducts btnMoreInfo_Click code and the frmCatalogDetails code in case one is messing up the other.

Private Sub btnMoreInfo_Click()
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim str As String
    Dim row As Long
    Set db = CurrentDb
    Set rs = db.OpenRecordset("tblProducts", dbOpenSnapshot)

        If Me.lstSearchResults.ItemsSelected.Count > 0 Then

            ' Debug.Print Me.lstSearchResults.Column(0)
            row = Me.lstSearchResults.Column(0)
            rs.MoveFirst
            rs.FindFirst "ProductID=" & row
            Debug.Print rs("Description")
            DoCmd.OpenForm "frmCatalogDetails", acNormal, , "ProductID=" & Me.lstSearchResults.Column(0, Me.lstSearchResults.ItemsSelected), acFormReadOnly, acWindowNormal

        Else
            MsgBox "You must select a product"
            Exit Sub
        End If
End Sub

and Catalog details

Option Compare Database
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim fld As DAO.Field

Private Sub Form_Load()

    Set db = CurrentDb

    'Set rs = db.OpenRecordset("tblProducts", dbOpenSnapshot)


    'Set fld = rs("image")

    Debug.Print rs("ProductID")
    Debug.Print rs("Description")
    'me.ctlImage.ControlSource =

    'Me.ctlImage.CurrentAttachment = fld.Value    
End Sub

The rs statements are commented out because I am having trouble with this form recognizing the rs from the parent form. I am getting a with block variable not set, but if I do rs.openRecordSet then the recordset goes back to the first row. Aside from your answer above, I have seen very little about manipulating the attachment object and the help has been difficult as it doesn't even cover accessing inside the attachment field. I am at a point where I will do more asking than answering on this topic, and I very much appreciate the time many of you take to craft an answer. Rollin Motto: Ask for help when needed, give help when asked, and remember where you came from.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!