Display multiple attachments in microsoft access 2

2020-02-11 06:41发布

问题:

I was initially very pleased to discover the attachment field in Access 2010. It's a feature that aesthetically irks my inner database purist but my inner lazy sod is in charge here and it does look, on the face of it, like it could make one of my current projects much easier/simpler. Happily it displays pictures/icons automatically on the forms and reports but (why is there always a but eh!) it only displays the first one and I need it to display all of them.

You can of course scroll through the attachments one at a time but I'm pretty sure my client won't wear that, despite his request that I complete the project in MS-Access which, seemingly, only has very rudimentary built in options for display :/ BUT...

I may well be wrong, I've got almost no MS-Access experience. My coding background is firmly LAMP stack and web so I'm deeply ignorant of what's on offer in the Windows/Access ecosystem. I suspect there are excellent 3rd party reporting tools that give very flexible layout but I need to see all the attachments on the form, not just the reports.

So, blundering blindly into the void my initial strategy is this...

Create a separate table for attachments where each field is an "attachment" containing a single item only. Then use scripting in the forms and reports to...

  1. Query that table for all attachments belonging to the record in question
  2. Display/Format those fields as some sort of list
  3. Dynamically append a fresh attachment field to the end of that list so the user has somewhere to upload a next attachment
  4. Make the form page refresh whenever an attachment is added so there's aways a free one.

So, my questions are...

  1. Is what I describe feasible in Access?
  2. Am I missing a much simpler / better / canonical solution?
  3. How powerful is Access's scripting language(s) with reference to display? i.e clunky or pixel perfect?
  4. It's not still Visual Basic is it? (noooooo! ;)
  5. If so are there any other scripting languages I can use within forms/reports?

Sorry, I know it's a bit of a long wooly question but I'm a fish out of water here!

Thanks,

Roger

回答1:

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:



回答2:

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.