UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Correct Messageobject.sendusingaccount Syntax, Office 2010    
 
   
rmd1401
post Apr 10 2012, 12:53 PM
Post #1

UtterAccess Addict
Posts: 123



Let me preface this with the following:
I am using Outlook 2010 connected to an Exchange 2010 server. I am setup on my primary account. I have access to several other accounts.
-I am given access to these accounts via Account Settings > Change > Change Account Dialog 'More Settings' > Next Screen 'Advanced Tab' > 'Open These Additional Mailboxes'.

>I am currently have a bunch of emails that are created by Access through the Outlook object model using VBA. I then switch the email account to the appropriate secondary account using the dropdown available.

>While the above is fine and good for one-off emails (though annoying), I am putting together a function to do some batch emailing that I won't interface with (I kick-off projects with a custom bulk message to each person, not a BCC to everyone). Thus, since I won't be want to change each email, I am trying to figure out how to use the '.SendUsingAccount' method to change the sender to the appropriate secondary account. It is not as easy a setting it to correctemail@noname.com. I have to create, and then identify the object, which I do not understand, as I do not even know what attributes identify these secondary accounts.

I am pretty proficient in VBA, but I do not understand the Outlook object model that well. I've of course tried F1 on .SendUsingAccount, but the example is unclear for my circumstance. Anyone have more experience with this?

Your help is greatly appreciated. Let me know if you need more information.
Go to the top of the page
 
+
Bob G
post Apr 10 2012, 12:58 PM
Post #2

UtterAccess VIP
Posts: 8,191
From: CT



I do not have 2010, however, if you could post the code that you have now that works, it will give others a good baseline.
Go to the top of the page
 
+
rmd1401
post Apr 10 2012, 01:39 PM
Post #3

UtterAccess Addict
Posts: 123



Here is the code I am using. I mention below where I am hoping to implement the new part, using CAPS.
CODE
Public Sub SubName (lngTime As Long)

Dim objOutlook As Outlook.Application
Dim mesMessage As MailItem
Dim strUserEmail As String
Dim strBusinessLeadEmail As String
Dim strSecondaryLeadEmail As String
Dim strIntegrationName As String
Dim strAddendum As String
Dim strAction As String

Set objOutlook = CreateObject("Outlook.Application")
Set mesMessage = objOutlook.CreateItemFromTemplate(Nz(DLookup("[strOutreachLetterEmailPath]", "[tblIntegrationSite]", "[pkcIntegrationSiteCN] = Forms!frmManageSupplierAccessRequest![fknIntegrationSiteCN]")))

strUserEmail = DLookup("strContactEmail", "tblSupplierList", "pkcRequestId = Forms!frmManageSupplierAccessRequest![pkcRequestId]")
strBusinessLeadEmail = Nz(DLookup("strBusinessLeadEmail", "tblIntegrationSite", "pkcIntegrationSiteCN = Forms!frmManageSupplierAccessRequest![fknIntegrationSiteCN]"), "")
strSecondaryLeadEmail = Nz(DLookup("strSecondaryLeadEmail", "tblIntegrationSite", "pkcIntegrationSiteCN = Forms!frmManageSupplierAccessRequest![fknIntegrationSiteCN]"), "")

strIntegrationName = Nz(DLookup("strIntegrationSiteEmailName", "tblIntegrationSite", "pkcIntegrationSiteCN = Forms!frmManageSupplierAccessRequest![fknIntegrationSiteCN]"))

Select Case lngTime

    Case 1
    
        strAddendum = ""
        strAction = "Sent 1st Email"
        
    Case 2
    
        strAddendum = " 2nd Attempt"
        strAction = "Sent 2nd Email"
    
    Case 3

        strAddendum = " 3rd Attempt"
        strAction = "Sent 3rd Email"

End Select

mesMessage.To = strUserEmail
mesMessage.CC = strBusinessLeadEmail & ";" & strSecondaryLeadEmail
mesMessage.Subject = "* " & strIntegrationName & " ******** (Action Required)" & strAddendum

mesMessage.SendUsingAccount '// THIS IS THE PART I WANT TO ADD BUT AM UNCERTAIN ABOUT, AS I HAVE TO IDENTIFY AN SECONDARY ACCOUNT OBJECT, OF WHICH I HAVE NO IDEA HOW TO DO.
mesMessage.Send '// WILL BE ADDING THIS PART WHEN I CAN CORRECTLY CREATE THE SEND USING ACCOUNT

mesMessage.Display (True)

Set objOutlook = Nothing
Set mesMessage = Nothing

If (MsgBox("Did you send the message?", vbYesNo, "Confirm") = vbYes) Then

    Forms![frmManageSupplierAccessRequest]![fsubSupplierRequestAction].Form.Recordset.AddNew
    Forms![frmManageSupplierAccessRequest]![fsubSupplierRequestAction]![txtActionType] = strAction
    Forms![frmManageSupplierAccessRequest]![fsubSupplierRequestAction]![txtActionDate] = Date
Else
    
    'do nothing

End If

End Sub


This post has been edited by rmd1401: Apr 10 2012, 01:42 PM
Go to the top of the page
 
+
rmd1401
post Apr 12 2012, 10:47 AM
Post #4

UtterAccess Addict
Posts: 123



I tried using the below:
CODE
Dim objAccount As Outlook.account
objAccount = objOutlook.Session.Accounts.Item("appropriateaddress@thiscompany.com")
mesMessage.SendUsingAccount = objAccount
mesMessage.Send


I got runtime error 91: object variable or block not set.

It is an secondary exchange account that I have send/recieve rights to.
Go to the top of the page
 
+
rmd1401
post Apr 16 2012, 11:46 AM
Post #5

UtterAccess Addict
Posts: 123



I have found info at this link, but cannot seem to translate it into something that capturing the secondary accounts:
http://msdn.microsoft.com/en-us/library/ff868195.aspx

I have tried putting the following aircode together, but it is not valid, and I can't seem to figure out how to loop through the secondary accounts to get the right information to build some later code.

I have managed to loops through my accounts with other code, but only one comes up (the primary).

CODE
Sub Test()
Dim objOutlook As Outlook.Application
Dim mesMessage As MailItem


Set objOutlook = CreateObject("Outlook.Application")
Dim oAccount As Outlook.Account


Dim nsOutlook As Outlook.Namespace
Set nsOutlook = objOutlook.GetNamespace("MAPI")

Do While nsOutlook.Accounts.DeliveryStore.ExchangeStoreType = OlExchangeStoreType.olAdditionalExchangeMailbox <<<<Not valid syntax, just an example

    Debug.Print oAccount.UserName

Loop



End Sub


I am really lost. But I cannot imagine that this could be so complicated, since I can easily select the secondary account in the MailItem UI when I have an outlook message up.
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 19th June 2013 - 06:47 AM