I am trying to accomplish something using the attachment controls on a form and an attachment field in a table. Each row in the attachment field will have a picture file and a pdf file with a more detailed product description. I have set up a product form to search products and display a list, but I also included a more info button to open another form with two unbound attachment controls which have as their row source the attachment field from the product table. The code in my button simply searches for the productID of the listbox selection and then opens the second form with the listbox selection in the where clause of the doCmd.openForm. When the second form opens both controls display the first attachment picture file of the current row. I have been trying to assign the second attachment control to the pdf file at the on_load event of the second form, but I can't seem to access the individual members of the attachment control. Those being attachmentField.FileData(1) and (2)
I have tried many different approaches to access that second file in the field and place it into the second control to no avail. I haven't tried a querydef and sql qry yet, but I have tried everything else days of research have revealed. Should I try a queryDef? Here is my code for the more info button on the product catalog form.
Code:
Private Sub btnMoreInfo_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim row As Long
Set db = CurrentDb
Set rs = db.OpenRecordset("tblProducts", dbOpenSnapshot)
If Me.lstSearchResults.ItemsSelected.Count > 0 Then
' This gets the product ID of the current selection of the listbox at column zero
' The value is used to set the current record and that is passed to the open form cmd
row = Me.lstSearchResults.Column(0)
rs.MoveFirst
rs.FindFirst "ProductID=" & row
' This opens the new form at the desired record as read only as intended for an informational form
DoCmd.OpenForm "frmCatalogDetails", acNormal, , "ProductID=" & Me.lstSearchResults.Column(0, Me.lstSearchResults.ItemsSelected), acFormReadOnly, acWindowNormal
Else
' just to make sure a listbox item is selected if not end sub returns the user to the form
MsgBox "You must select a product"
Exit Sub
End If
End Sub
The bit of code in my second form on_load event is this:
Code:
Private Sub Form_Load()
Set db = CurrentDb
Dim doc As DAO.Document
' Set doc = rs.Fields("image") ' image is the name of the attachment field/column
' Debug.Print ctlFeatures.CurrentAttachment
End Sub
Screen shots of forms: I would like the picture in control 1 and pdf in control 2
