Save off attachment and start SQL stored procedure

W

Webtechie

Hello,

I have programmed using VBA for Excel, Word and Access before. However,
never Outlook.

1) But I need to check folders for mail from out clients.
2) If I find mail from out clients, I need to save off the attachment in a
certain folder
3) Then I want to kickoff a SQL Server stored procedure

Now having said that, can anyone at least point me in the right direction?

Can you set up a macro to run at intervals throughout the day?
Can you save off the attachments?
And of course, how to execute a SQL Server stored procedure?

Thanks for any and all help in my getting started with this.

Tony
 
K

Ken Slovak - [MVP - Outlook]

Running a macro at specified times or at intervals is not supported out of
the box. You would need to use a timer to fire at intervals to kick-start
the process. Since VBA code doesn't provide a timer control you would need
to have either VB6 installed and use its timer control or use a Win32 API
timer control. You can find VB6 code for a Win32 API timer at
www.vbaccelerator.com and modify that as needed to work in your VBA code.

You can save attachments from specific items to the file system, there's
code to remove attachments from selected items at
http://www.slovaktech.com/code_samples.htm#StripAttachments that could be
used as a starter for your code.

How you call a stored procedure in SQL Server depends on how you're
connecting to the SQL server and is out of scope for this newsgroup. You
will need to specify how you're connecting, for example using ADO or
whatever.
 
W

Webtechie

Ken,

Thanks for your response.

I found code to save off attachments. I just don't know how to execute the
procedure upon arrival on new mail.

I know you can create a rule based on when mail arrives, but I didn't know
if you could run a VBA procedure that way.

I disagree about my question about SQL Server being outside the scope of
this forum.

If I need to run something from Outlook, to me that is in scope!

I wasn't sure if I could use the same ADO recordset commands that I used to
connect EXCEL VBA to SQL Server in Outlook VBA.

Again thanks for your response.


Tony
 
K

Ken Slovak - [MVP - Outlook]

If you want to execute your code when new items arrive rather than at timed
intervals you can use a script executed from a rule or you can directly
handle either the NewMailEx event or the Inbox.Items.Add event. The script
executed from a rule is a public macro with this signature:

Sub myRuleScriptOrWhateverName(item As MailItem)

For information on the Items.Add event search for "zaphtml" at
www.outlookcode.com and for NewMailEx just search on that there. There are
lots of code samples there for that sort of thing.

Whether it's Outlook or Excel or Word VBA or VB6, if you're using ADOB then
executing stored procedures is identical. Same for any other connection
method you want to use. That's what's out of scope for this group, we don't
delve into the intricacies of SQL Server or other DB work.
 

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