SendUsingAccount to change from account

P

p912s

Hello! I have searched all over the web and have been unable to locate a
solution... the closest I came was this thread -
http://www.thecodecage.com/forumz/o...-outlook-sendusingaccount-change-account.html

My problem is sending a message after changing the sending account in VBA. I
get an error - "You Cannot Send An Item That Is Already In The Process Of
Being Sent"

And here is my code - fairly simple, it gathers up the pop3 accounts and
presents them in a popup message to select the account to send from. The
selecting and changing accounts works fine but the messages can't be sent. I
have documented in the code where the error happens.

Thanks.




Option Explicit

Private Sub Application_ItemSend(ByVal item As Object, Cancel As Boolean)
Exit Sub
Dim oAccount As Outlook.Account
Dim strDefaultAccount As String, strMsg As String, strID As String
Dim strAccounts(100)
Dim c As Integer, i As Integer
Dim result As Variant

c = 1

'get default account
strDefaultAccount = Application.Session.Accounts(1).DisplayName

'get pop3 accounts
For Each oAccount In Application.Session.Accounts
If oAccount.AccountType = olPop3 Then
strAccounts(c) = c & " - " & oAccount
'Debug.Print strAccounts(c)
c = c + 1
End If
Next

'build inputbox account list
strMsg = "Click Ok to use default account or enter the number of the
account to use...." & vbCrLf
For i = 1 To c
strMsg = strMsg & vbCrLf & strAccounts(i)
Next i

'********************************************************
'message id
'I think this is the id i need to recall and send the message?
strID = item.ConversationIndex
'********************************************************

'display inputbox
result = InputBox(strMsg, "Select Sending Account", strDefaultAccount)

'act on user input
Select Case result
Case strDefaultAccount
'clicked ok - send from default account
Cancel = True
Set item.SendUsingAccount = Application.Session.Accounts(1)
'********************************************************
'send error - "You Cannot Send An Item That Is Already In The
Process Of Being Sent"
item.Send
'********************************************************
Case IsNumeric(result)
'typed a number - send from account entered
If result <= i Then
Cancel = True
Set item.SendUsingAccount =
Application.Session.Accounts(result)
'********************************************************
'send error - "You Cannot Send An Item That Is Already In
The Process Of Being Sent"
item.Send
'********************************************************
Else
'entered incorrect number - stay in message
Cancel = True
End If
Case Else
'clicked cancel or invalid entry - stay in message
Cancel = True
End Select
End Sub
 
D

Dmitry Streblechenko

Try to cancel the submission by setting theancel parameter to true, then
re-submit the message after setting the SendUsingAccount property.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
 
P

p912s

Dmitry said:
Try to cancel the submission by setting theancel parameter to true,
then
re-submit the message after setting the SendUsingAccount property.
[/QUOTE]

Isn't that what I have done here? I'm canceling, setting the account
and then trying to send.
 
D

Dmitry Streblechenko

You need to resubmit the message when you are out of the ItemSend event
handler. You can use a timer for that.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-

Isn't that what I have done here? I'm canceling, setting the account
and then trying to send.
[/QUOTE]
 

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