Results 1 to 3 of 3
  1. #1
    tommyried is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    May 2012
    Posts
    38

    updating attachments through code

    hi everyone

    I want to update my attachments in below table through code for example I will have one command button to pick another file and save it to the old attachment field as per vendor because my attachments are updating weekly basis I don't want to add it manually.


    Vendors ID Subsystem ID Vendors Name Attachment
    1 1 microsoft 1
    2 1 sun 1
    3 1 christie 1
    4 2 unicon 1


  2. #2
    drexasaurus's Avatar
    drexasaurus is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    Santa Ana, CA
    Posts
    60
    I don't have a lot of experience with the attachment data type, but to update these attachments through code, you will have to use the Recordset2 type of Recordset object (the recordset type added to access to deal with these new data types), and the Field2 type. Attachments are a type of multi-value field, and are navigated by referencing the value of the attachment field as second recordset object that you can use to iterate over the different attachments. Here is a brief example to give you an idea, naturally useful code will be much more involved (not tested, so test thoroughly first):

    Code:
    dim rst1 as DAO.Recordset2, rst2 as DAO.Recordset2, fld as DAO.Field2, db as DAO.Database
    Set db = CurrentDb
    Set rst = db.OpenRecordset("TableWithAttachmentsHere")
    If not rst.EOF and not rst.BOF then
       Set fld = rst("AttachmentField")
       Set rst2 = fld.Value
       Do While Not rst2.EOF
          'Some Code here
       rst2.MoveNext
       Loop
    End If
    There are functions part of Field2 that are used to change this file data. In the example, to add a new file, you would use (after AddNew), rst2("FileData").LoadFromFile yourPathVariable. To save the file to disk, rst2("FileData").SaveToFile yourPathVariable. To delete the file (which it seems you want to do first), run delete on the record you want to delete (simply rst2.Delete).

  3. #3
    tommyried is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    May 2012
    Posts
    38
    sorry I didn't understand this code.if u can send me a sample DB it would be a great help to me .

    thanks

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 01-29-2014, 03:19 PM
  2. getting outlook attachments using vba code
    By umenash in forum Access
    Replies: 3
    Last Post: 10-02-2013, 12:15 PM
  3. attachments
    By chiefmsb in forum Forms
    Replies: 0
    Last Post: 07-12-2011, 07:32 AM
  4. attachments
    By chiefmsb in forum Access
    Replies: 0
    Last Post: 07-10-2011, 07:38 PM
  5. attachments
    By chiefmsb in forum Access
    Replies: 0
    Last Post: 07-08-2011, 03:56 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums