Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    Dec 2014
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Attaching a word document to the attachment field for every new record

    Hi

    I'm working on a database to enter data in various forms. One of the forms has a attachment field in the Table.
    Is there a way to attach a default word document to this field when I add a new record. I can add the doc
    manualy in the form by clicking the attachment box, but it would solve my problem if this doc was there already,
    then all I would have to do is double click the attachment to open up word to edit the file.

    Can this be done or am I dreaming. I have tried to construct a bit of code to the forms properties using
    AttachmentData.LoadFromFile("C:\Sample.docx")but I keep running into a brick wall.

    Regards,

    Ken

  2. #2
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,624
    Thanks
    3
    Thanked 60 Times in 60 Posts
    I presume you are working with the .accdb format where you can attach various types of documents to a record, and that you are working with Access 2007/2010/2013. There are some issues with attaching documents as they do tend to bloat your database and can cause you to bump up against the 2GB limit, but they are significantly less than with the .mdb format where embedded documents caused a huge bloat.

    I think the article Access 2013 use attachment field to attach and rename a document will point you in the right direction, but note that there is a side discussion about how to store just to the path to the Word document, which is how it is typically done with the .mdb database. If that turns out to be confusing, post back and we will try to give you a hand.
    Wendell

  3. The Following User Says Thank You to WendellB For This Useful Post:

    KenGra (2015-01-11)

  4. #3
    New Lounger
    Join Date
    Dec 2014
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thanks Wendell will check it out and come back when confused.
    Ken

  5. #4
    New Lounger
    Join Date
    Dec 2014
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Close but not Close Enough

    Yes it is Access 2010.
    ok so I have got this far and now I'm stuck. The following code work's fine if I add it to the On Load Event on the Form, but the doc is attach'd to the first record. When I add the code to the Add New Record button, I get the error msg: "File already part of the Multi-Valued Field" and nothing in the attachment field. I can't work out what is going on.

    Code:
    Private Sub Add_Record_Click()
    
    DoCmd.GoToRecord , , acNewRec
    Me.Description.SetFocus
    
    On Error GoTo Err_AddImage
    
     Dim db As DAO.Database
     Dim rsParent As DAO.Recordset2
     Dim rsChild As DAO.Recordset2
      
        
        Set db = CurrentDb
        Set rsParent = Me.Recordset
        
        rsParent.Edit
        
        Set rsChild = rsParent.Fields("Photo").Value
    
        rsChild.AddNew
        rsChild.Fields("FileData").LoadFromFile ("C:\Users\Public\Sample.docx")
    rsChild.Update
    rsParent.Update
    
    Exit_AddImage:
    
     
        Set rsChild = Nothing
        Set rsParent = Nothing
      
    Exit Sub
    
    Err_AddImage:
    
    If Err = 3820 Then
    MsgBox ("File already part of the multi-valued field!")
    Resume Next
    
    Else
    MsgBox "Some Other Error occured!", Err.Number, Err.Description
    Resume Exit_AddImage
    
    End If
    
    End Sub
    Regards
    Ken
    Last edited by KenGra; 2015-01-13 at 07:17.

  6. #5
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,624
    Thanks
    3
    Thanked 60 Times in 60 Posts
    Off the top of my head, it appearss to me that you are using the full recordset with the statement "set rsParent = Me.Recordset" where Me. refers to the form you are currently in. However I can't see the full form design so you may have restricted the recordset for the form. Is that the case?
    Wendell

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •