Save Attachment via VBA

R

Roger Converse

Hello,

I have my inbox linked to an Access DB. Is there a way to create a macro
that will save an attachment from an e-mail? If so, what would be a
difficulty level of completing? Basically, I would like to setup some
criteria in access that decides if an e-mail has an attachment and keyword in
the subject line, then call object Outlook and save the attachment. At that
point, Access would take back control and run a routine.

I have coded VB in Excel and Access, but never Outlook.

Any suggestions welcome!

Thank you,
Roger
 
E

Eric Legault [MVP - Outlook]

You have the Has Attachments column in an imported or linked table from an
Outlook folder to determine if an attachment is present (value = -1).
However, you do not have the EntryID value to work with to uniquely identify
the message to retrieve using the Outlook Object Model. First you'll have to
use the AdvancedSearch method to return a Results collection to find the
message in question. This will require two criteria:

1) The DASL property for finding an attachment:
"urn:schemas:httpmail:hasattachment" = 1
2) One or more other DASL properties that can help retrieve a unique e-mail,
necessary if there are e-mail threads with duplicate sender names and subject
lines. One property search example would be "urn:schemas:mailheader:subject
= 'Office Holiday Party'". You would need to concatenate multiple critieria
with the AND keyword. However, keep in mind you are limited to the
properties that are exposed to Access (and hence the Outlook DASL equivalent
property names).

You can easily build your search critieria by creating a view and using the
options in the Filter property sheet - then switch to the SQL tab to see the
full search syntax.
 
R

Roger Converse

So, just to make sure I understand, you are saying that I can control this
all through Access VB and I won't have to create a macro in Outlook?

Thanks,
Roger
 
E

Eric Legault [MVP - Outlook]

It really depends on where you want the code to run. You either set a
reference to the Outlook Object Model in your Access project and read your
table data there through whatever means makes sense (bound control calling a
function, Access macros, ADO/DAO, etc.), or use ADO or DAO in an Outlook
macro to read your table data.

--
Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/
 
R

Roger Converse

Thank you for the replies, BTW. I think I forgot that on my other post.

Well, it would probably be ideal if I could keep everything in Access.

I checked the AdvancedSearch function in Access and was not even sure what
that meant? What would the scope as string be?

I am going to look at it much more tonight when I get home, but I was
definitly lost in your points 1 + 2 from your previous post. What is DASL?

I also don't know what this is: "You can easily build your search critieria
by creating a view and using the options in the Filter property sheet - then
switch to the SQL tab to see the full search syntax."

Are you referring to the design view for queries? I am confused by
"property search".

Thank you,
Roger
 
E

Eric Legault [MVP - Outlook]

Your welcome Roger!

The AdvancedSearch function is in Outlook:

AdvancedSearch Method:
http://msdn2.microsoft.com/en-us/library/aa220071(office.11).aspx

Info on DASL:

Tips for DASL searches:
http://www.outlookcode.com/news.aspx?id=30

You use the Create View dialog in Outlook as the tool to help build the
search strings for the AdvancedSearch method. Let me know if you need
anything clarified.

--
Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top