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