PC Review Forums Newsgroups Microsoft Outlook Microsoft Outlook VBA Programming Why does this code not work (Change Sender Acct)?

Reply

Why does this code not work (Change Sender Acct)?

 
Thread Tools Rate Thread
Old 04-05-2004, 09:15 AM   #1
Sanjay Singh
Guest
 
Posts: n/a
Default Why does this code not work (Change Sender Acct)?


I am using code copied at end of this message to try and change the "send
from" account. Code is based on Sue Mosher's Book example. For some reason
the Send From address does not change. I stepped through the code to check
and the Execute line gets run as expected. The problem appears to be that
the Send From Account does not get changed even throug the line is run. I am
using Outlook 2003.

Any help will be greatly appreciated.
Thanks in advance
Sanjay

Option Explicit
Const ACCT_TO_USE = "Someaccount"

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
'How can we get the name of the account that will be used to send

Dim objInsp As Outlook.Inspector
Dim colCB As Office.CommandBars
Dim objCBAccounts As Office.CommandBarPopup
Dim objCBB As Office.CommandBarButton
Dim blnAccountFound As Boolean


Set objInsp = Item.GetInspector
Set colCB = objInsp.CommandBars
Set objCBAccounts = colCB.FindControl(ID:=31224)
Set objCBB = objCBAccounts.Controls.Item(1)

If Not objCBB Is Nothing Then
If objCBB.Caption <> ACCT_TO_USE Then
Set objCBB = Nothing
For Each objCBB In objCBAccounts.Controls
If InStr(1, objCBB.Caption, ACCT_TO_USE, vbTextCompare) > 0
Then
blnAccountFound = True
Err.Clear
objCBB.Execute

Exit For
End If
Next
End If

If blnAccountFound = False Or Err.Number <> 0 Then
Cancel = True
End If
End If

Set objInsp = Nothing
Set colCB = Nothing
Set objCBAccounts = Nothing
Set objCBB = Nothing

End Sub


  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off