BrokenBiker
ManicMechanic
- Local time
- Today, 12:27
- Joined
- Mar 22, 2006
- Messages
- 128
Many people are interested in managing attachments in Access 2007, but there isn't much info out there. I was able to find a little something on the subject.
However, the line of code for exporting (.SaveToFile) will only 'Save As' one attachment in the one record for the form. I added a little basic 'Loop' to have it actually 'SaveAs' x amount of attachments. It works great...on the individual record.
I tried to apply the same logic/loop to have it loop through the entire table the form is based on, but I get "Some Other Error occured!"...and it doesn't proceed to the next record.
So, is there a way to have it loop through a record and through the entire table of records?
Any help is greatly appreciated.
-BB
However, the line of code for exporting (.SaveToFile) will only 'Save As' one attachment in the one record for the form. I added a little basic 'Loop' to have it actually 'SaveAs' x amount of attachments. It works great...on the individual record.
Code:
On Error GoTo Err_SaveImage
Dim db As DAO.Database
Dim rsParent As DAO.Recordset2
Dim rsChild As DAO.Recordset2
Set db = CurrentDb
Set rsParent = Me.Recordset
rsParent.OpenRecordset
Set rsChild = rsParent.Fields("Attachment_CrsList").Value
With rsChild
Do Until .EOF
.MoveFirst
rsChild.OpenRecordset
rsChild.Fields("FileData").SaveToFile ("C:\Users\Broken.Biker\Desktop\Test")
rsChild.Delete
Me.Refresh
.MoveNext
Loop
.Close
MsgBox "Record cw"
End With
Exit_SaveImage:
Set rsChild = Nothing
Set rsParent = Nothing
Exit Sub
Err_SaveImage:
If Err = 3839 Then
MsgBox ("File Already Exists in the Directory!")
Resume Next
Else
MsgBox "Some Other Error occured!", Err.Number, Err.Description
Resume Exit_SaveImage
End If
I tried to apply the same logic/loop to have it loop through the entire table the form is based on, but I get "Some Other Error occured!"...and it doesn't proceed to the next record.
Code:
On Error GoTo Err_SaveImage
Dim db As DAO.Database
Dim rsParent As DAO.Recordset2
Dim rsChild As DAO.Recordset2
Set db = CurrentDb
Set rsParent = Me.Recordset
rsParent.OpenRecordset
Set rsChild = rsParent.Fields("Attachment_CrsList").Value
With rsParent
Do Until .EOF
.MoveFirst
With rsChild
Do Until .EOF
.MoveFirst
rsChild.OpenRecordset
rsChild.Fields("FileData").SaveToFile ("C:\Users\Broken.Biker\Desktop\Test")
rsChild.Delete
Me.Refresh
.MoveNext
Loop
.Close
MsgBox "Record cw"
End With
.MoveNext
Loop
.Close
MsgBox "Recordset done, son!"
End With
Exit_SaveImage:
Set rsChild = Nothing
Set rsParent = Nothing
Exit Sub
Err_SaveImage:
If Err = 3839 Then
MsgBox ("File Already Exists in the Directory!")
Resume Next
Else
MsgBox "Some Other Error occured!", Err.Number, Err.Description
Resume Exit_SaveImage
End If
So, is there a way to have it loop through a record and through the entire table of records?
Any help is greatly appreciated.
-BB
Last edited: