Auto add an attachment template when a new record is created.

scopes456

Registered User.
Local time
Today, 17:54
Joined
Feb 13, 2013
Messages
88
I have a database I use to handle orders. I have a pdf template that when a new order is added to the system my users attach this pdf to the record.

I would like when I create a new record that the attachment is automatically copy from a default location onto the record. So users does not have to manually add to the system .


Is this possible?
 
This thread had some code which I tried in the attached database and it seems to work fine. I put the code in the after update of the form so it adds the attachment each time a record is added. The code is

Code:
On Error GoTo Err_AddImage

Dim db As DAO.Database
Dim rsParent As DAO.Recordset2
Dim rsChild As DAO.Recordset2

Set db = CurrentDb
Set rsParent = Me.Recordset

rsParent.Edit

'Change AttachmentTest to the field name of the attachment
Set rsChild = rsParent.Fields("AttachmentTest").Value

rsChild.AddNew

'change C:\Users\sneuberg\Desktop\clock.bmp to the path of the attachment
rsChild.Fields("FileData").LoadFromFile ("C:\Users\sneuberg\Desktop\clock.bmp")

rsChild.Update
rsParent.Update

Exit_AddImage:

Set rsChild = Nothing
Set rsParent = Nothing
Exit Sub

Err_AddImage:

If Err = 3820 Then
MsgBox ("File already part of the multi-valued field!")
Resume Next

Else
MsgBox "Some Other Error occured!", Err.Number, Err.Description
Resume Exit_AddImage

End If

I've added comments to it to indicate where you need to change it to adapt it to your situation.
 

Attachments

Last edited:
sneuberg thank you
 

Users who are viewing this thread

Back
Top Bottom