none
Access File Attachment LoadFromFile not working RRS feed

  • Question

  • Hello.  I am trying to remove all file attachments from a record and add one file attachment in the following sub.  The code removes the files just fine.  Stepping through, it seems to be doing the job, but the attachment does not actually get added.  I have no idea what I am doing wrong:

    Public Sub AttachSketchFile(ByRef rstCurrent As DAO.Recordset, ByVal strFieldName As String, SketchFile As String, RecordNumber As String)
        Dim fldAttach As DAO.Field2
        Dim Sketches As DAO.Recordset2
        
        'set the current record of the record set
        rstCurrent.Index = "PrimaryKey"
        rstCurrent.Seek "=", RecordNumber
        'delete all files  (works good)
        Set fldAttach = rstCurrent(strFieldName)
        Set Sketches = fldAttach.Value
        Do While Not Sketches.EOF
            Sketches.Delete
            Sketches.MoveNext
        Loop
        
        
        'set the current record again
        rstCurrent.Index = "PrimaryKey"
        rstCurrent.Seek "=", RecordNumber
        
        'add new file  (it seems to work when stepping through, but does not actually add the file.)
        Set fldAttach = rstCurrent(strFieldName)
        Set Sketches = fldAttach.Value
        rstCurrent.Edit
        Sketches.AddNew
        Sketches("FileData").LoadFromFile SketchFile
        Sketches.Update
        Sketches.Close
        Set fldAttach = rstCurrent(strFieldName)
        Set fldAttach = Nothing
    End Sub

    Thursday, December 11, 2014 8:31 PM