Results 1 to 3 of 3
  1. #1
    PoolHallJunkie is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2014
    Posts
    14

    Attaching files to a New Record in a table

    Good Afternoon,



    The code below looks up a file path that has been placed in a listbox "Attachments" and is supposed to create a new record and attach it to the attachments field "Evidence". Currently it only attaches the file to the 1st record in the table. Is there a way to make it create a new record and attach it to that?

    Code:
     Private Sub cmdImport_Click()
        Dim dbs As Database
        Dim rst As Recordset2
        Dim arst As Recordset2
        Dim fld As Field2
        
        Dim aFile
        
        Set dbs = CurrentDb
        Set rst = dbs.OpenRecordset("VRM Evidence")
        Set fld = rst("Evidence")
        
        rst.AddNew
        rst.Edit
            
        Set arst = fld.Value
    On Error GoTo Proc_Error
    For aFile = 0 To Me.Attachments.ListCount - 1
        With arst
            .AddNew
            .Fields("FileData").LoadFromFile (Me.Attachments.ItemData(aFile))
            .Update
            .Close
        End With
    Next
        rst.Update
        
        Set rst = Nothing
        Set dbs = Nothing
        
    Proc_Exit:
      Exit Sub
    Proc_Error:
      MsgBox "Error " & Err.Number & " in cmdImport.Click" & vbCrLf & Err.Description
      Resume Proc_Exit
    
    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Remove the rst.Edit line.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    PoolHallJunkie is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2014
    Posts
    14
    Gah! That was it?!

    Works perfectly, thank you!

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

Similar Threads

  1. attaching files to an email via a MACRO
    By bobandtom in forum Macros
    Replies: 22
    Last Post: 10-29-2013, 10:25 AM
  2. Replies: 1
    Last Post: 08-01-2013, 01:32 PM
  3. Size concern with attaching files.
    By chrisfl in forum Access
    Replies: 2
    Last Post: 04-17-2013, 10:20 AM
  4. Attaching Files
    By jlclark4 in forum Forms
    Replies: 7
    Last Post: 01-20-2011, 03:01 PM
  5. Attaching a file to a record
    By ildanach in forum Forms
    Replies: 0
    Last Post: 08-16-2008, 07:57 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