none
how to use for x with add attachment File Data vba RRS feed

  • Question

  • Helloooooooooooooooo all my friends

    i use that code to add attach to my table and it worked verry good

           Dim rsEmployees As DAO.Recordset
       Set db = CurrentDb
       Set rsEmployees = db.OpenRecordset("FileAttach")
      Dim rsPictures As Object
      Dim x As Integer
    
       ' Activate edit mode.
       rsEmployees.AddNew
      
       ' Instantiate the child recordset.
       Set rsPictures = rsEmployees.Fields("AttachForms").Value
          rsPictures.AddNew
    
    
       ' Add a new attachment.
    
       rsPictures.Fields("FileData").LoadFromFile "C:\Users\xmen5\Desktop\fl1.rar"
       rsPictures.Update
      
       ' Update the parent record
       rsEmployees.Update
    Next

    my proplem is when i use for x with that code

       Dim rsEmployees As DAO.Recordset
       Set db = CurrentDb
       Set rsEmployees = db.OpenRecordset("FileAttach")
      Dim rsPictures As Object
      Dim x As Integer
    
       ' Activate edit mode.
       rsEmployees.AddNew
      
       ' Instantiate the child recordset.
       Set rsPictures = rsEmployees.Fields("AttachForms").Value
        
    
    For x = 1 To DCount("*", "[Attchment]")
      rsPictures.AddNew
       ' Add a new attachment.
       rsPictures.Fields("FileData").LoadFromFile DLookup("[PathTxt]", "[Attchment]", "[id]=" & x & "")
       rsPictures.Update
      
       ' Update the parent record
       rsEmployees.Update
    Next

    it give me that error


    i take path of attachment from table so how i use for x with that code

    Saturday, January 14, 2017 10:28 PM

All replies

  • the answer is : Move the last line for update out of the loop: Next ' Update the parent record rsEmployees.Update
    Sunday, January 15, 2017 1:27 PM