Group:  Microsoft Outlook ยป microsoft.public.outlook.program_vba
Thread: Save off attachment and start SQL stored procedure

Geek News

Save off attachment and start SQL stored procedure
Webtechie 12/22/2008 2:44:01 PM
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
Re: Save off attachment and start SQL stored procedure
"Ken Slovak - [MVP - Outlook]" <kenslovak[ at ]mvps.org> 12/22/2008 7:15:45 PM
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.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Webtechie" <Webtechie[ at ]discussions.microsoft.com> wrote in message
news:D5FC408B-AA66-4928-B3A5-75F2BAC86A8A[ at ]microsoft.com...
[Quoted Text]
> 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

Re: Save off attachment and start SQL stored procedure
Webtechie 12/22/2008 7:46:07 PM
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

"Ken Slovak - [MVP - Outlook]" wrote:

[Quoted Text]
> 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.
>
> --
> Ken Slovak
> [MVP - Outlook]
> http://www.slovaktech.com
> Author: Professional Programming Outlook 2007.
> Reminder Manager, Extended Reminders, Attachment Options.
> http://www.slovaktech.com/products.htm
>
>
> "Webtechie" <Webtechie[ at ]discussions.microsoft.com> wrote in message
> news:D5FC408B-AA66-4928-B3A5-75F2BAC86A8A[ at ]microsoft.com...
> > 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
>
>
Re: Save off attachment and start SQL stored procedure
"Ken Slovak - [MVP - Outlook]" <kenslovak[ at ]mvps.org> 12/22/2008 8:47:23 PM
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.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Webtechie" <Webtechie[ at ]discussions.microsoft.com> wrote in message
news:38CB7F21-7A65-4A46-A8FA-2F057F35D3BD[ at ]microsoft.com...
[Quoted Text]
> 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

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net