Trying to do something I thought was simple. I create a bunch of reports from access various formats Excel and PDF. Grab the file created Attach it to an email and send it. The problem I am having is they need to be sent from different Users. Attached is the code I have been using and it sends just fine but it doesn't change login profiles so it is sent as a different user. When it gets the 1st user it sends all the remaining files as that user. I need the abaility to send as diffrent user so any question that come go to the customer service person not me.
We are using an exchange server and this was the only method I could see to get the mail in the users Sent items and make it look like the User sent the Items. Am I thinking right or am I way off course.
Here's the code that doesn't change Profiles.
Dim odjOutlook As Object
Dim myNameSpace As NameSpace
Set dbCustomerEMailReports = dbreporting.OpenRecordset("tblEMailtoGo")
dbCustomerEMailReports.MoveFirst
Do Until dbCustomerEMailReports.EOF
txtProfile = Trim(dbCustomerEMailReports.sysdba_CONTACT_1_LASTN AME) & Left(dbCustomerEMailReports.sysdba_CONTACT_1_FIRST NAME, 1)
Dim odjOutlook As Object
Dim myNameSpace As NameSpace
'Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
Set myNameSpace = objOutlook.GetNamespace("MAPI")
myNameSpace.Logon txtProfile, , False, True
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
'Add the To recipient(s) to the message.
'Set objOutlookRecip = .Recipients.Add("George Cornelius")
Set objOutlookRecip = .Recipients.Add("<Larry@prfood.com>")
'Set objOutlookRecip = .Recipients.Add(dbCustomerEMailReports.PrCSMEMail)
' Set objOutlookRecip = .Recipients.Add(Trim(dbCustomerEMailReports.sysdba _CONTACT_FIRSTNAME) & " " & Trim(dbCustomerEMailReports.sysdba_CONTACT_LASTNAM E) & " <" & dbCustomerEMailReports.MfgEmail & ">")
' Set the Subject, Body, and Importance of the message.
.Subject = dbCustomerEMailReports.txtSubject
.Body = "Dear " & Trim(dbCustomerEMailReports.sysdba_CONTACT_FIRSTNA ME) & " " & Trim(dbCustomerEMailReports.sysdba_CONTACT_LASTNAM E) & "," & Chr(13) & Chr(13) & _
dbCustomerEMailReports.txtBodyText
' Add attachments to the message.
txtAttachmentname = dbCustomerEMailReports.strReportFileName
Set objOutlookAttach = .Attachments.Add(txtAttachmentname)
' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
If Not objOutlookRecip.Resolve Then
objOutlookMsg.Display
End If
Next
.Send
'myNameSpace.Logoff
End With
myNameSpace.Logoff
MsgBox myNameSpace.CurrentUser
objOutlook.Quit
Set objOutlookAttach = Nothing
Set objOutlookMsg = Nothing
Set myNameSpace = Nothing
Set objOutlook = Nothing
txtProfile = Null
dbCustomerEMailReports.MoveNext
Loop
Exit_Command0_Click:
Exit Sub
Help
Thanks
Larry
larry@prfood.com



