OUTLOOK-Saving attachment to database

ChrisAnthony

Registered User.
Local time
Yesterday, 23:55
Joined
Oct 15, 2010
Messages
20
Hi all,

I have some code in my database that saves each email from a folder and stores the information in a table.... In this code it currently saves attachments to a specific directory.

Now I would like to save these attachments directly to the database instead of the directory.

Does anyone have code that can help me do this.

Thanks,
Chris
 
Sorry this article does not talk about saving attachments to the database

Thanks.
 
When you say saving it to the database what exactly do you mean? And what happens to multiple attachments and various formats of attachments. Alot more info needed.
 
So I have code that goes through each email item in a folder it saves all the email information to a new record in a table ie .sendername, .datereceived ect.

Currently for each mail item attachment it saves the file in a directory.
I want to change this part so it saves the attachment to the attachment field in my database.

Thanks,

Chris
 
Do you want to save the actual file in your database or just a link?


I think you have something like this but anyway here is some help on extracting the attachments.

Source is (but do not think the link works) http://www.experts-exchange.com/Sof...Info=1+10+30+attach+bluedevilfan+outlook+save


So this is not my code.

1. Start Outlook.
2. Click Tools->Macro->Visual Basic Editor.
3. If not already expanded, expand Modules and click on Module1.
4. Copy the code below and paste it into the right-hand pane of the VB Editor.
5. Edit the code as needed. I placed comment lines where things need to change.
6. Click the diskette icon on the toolbar to save the changes.
7. Close the VB Editor.
8. Click Tools->Macro->Security.
9. Change the Security Level setting to Medium.
10. Create a rule that runs when a new message arrives. Set it to check the subject for the text you want to trigger on. If found, set the rule to move the message to the "Car Mileage Claim" folder and to run the macro. The order is immaterial. The final rule should look something like this:

Apply this rule after the message arrives
with Car Mileage Claim in the subject
and on this machine only
move it to the Car_Mileage folder
and run Modules.SaveAttachmentsToDiskRule


Sub SaveAttachmentsToDiskRule(olkMessage As Outlook.MailItem)
Dim olkAttachment As Outlook.Attachment, _
objFSO As Object, _
strRootFolderPath As String, _
strFilename As String
'Change the path on the following line to the folder you want the attachments save in
strRootFolderPath = "C:\Car_Mileage_Attachments\"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set olkSourceFolder = Application.ActiveExplorer.CurrentFolder
If olkMessage.Attachments.Count > 0 Then
For Each olkAttachment In olkMessage.Attachments
strFilename = olkAttachment.FileName
intCount = 0
Do While True
If objFSO.FileExists(strRootFolderPath & strFilename) Then
intCount = intCount + 1
strFilename = "Copy (" & intCount & ") of " & olkAttachment.FileName
Else
Exit Do
End If
Loop
olkAttachment.SaveAsFile strRootFolderPath & strFilename
Next
End If
Set objFSO = Nothing
Set olkAttachment = Nothing
Set olkMessage = Nothing
End Sub
 
Thanks.... but the DB already does that. I need to save the file to the DATABASE not a directory on my harddrive!
 
Thanks.... but the DB already does that. I need to save the file to the DATABASE not a directory on my harddrive!

Then that is not an outlook attachment specific question, that is just "How do I save files to a database question".

I dont do it.

You might also find the common thought that saving files in a database causes the size of the database to expand faster than a chocolate lovers waistline.
 
Last edited:
You might also find the common thought that saving files in a database causes the size of the database to expand faster than a chocolate lovers waitline.

I agree completely - not worth doing, especially if using Access as a backend because of the 2gb limit.
 

Users who are viewing this thread

Back
Top Bottom