2017-01-14 11 views
0

Hellooooooooooooooooすべての私の友人 追加添付ファイルデータVBA

私は私のテーブルにアタッチ追加するためにそのコードを使用して、それがverry良い

 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

を働いたとのxに使用する方法私のプロンプラムは、そのコードでxに使用するときです。

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

それは私にそのエラー enter image description here

私はテーブル から添付ファイルのパスを取るを与えるので、私はそのコードとxに対して

答えて

0

移動ループのうち、更新のための最後の行を使用する方法:

Next 
' Update the parent record 
rsEmployees.Update 
+0

ありがとうございました私の友人moreeeeeeeeeその仕事は良い –

+0

どのように私はあなたの答えは最高の答えですか? –

+0

素晴らしい!答えをマークし、上三角をクリックしてください。 – Gustav

関連する問題