Outlook , VBA , two profiles

imfarhan

Board Regular
Joined
Jan 29, 2010
Messages
125
Office Version
  1. 2016
Platform
  1. Windows
Hi
I've got two main VBA code written on Outlook for Profile-A, which sending reports by using two VBA function and working fine now those functions are as follows :-

Code:
-----------------------------
(1)
CheckQueue() 
     'Recordset
      What it does is "RecordCout of 'rs' 
         If Found then 
             call the other function i.e.
               'Cycle through records
    For iCount = 1 To iMax
        'Create new Email from data returned from DB
        If GenerateEmail(rs!EmailTo & "", rs!EmailToCC & "", rs!Document & "", _
                        rs!BodyText & "", IIf(rs!AttachReport, rs!Attachment & "", "")) Then
        
            rs.Edit
            rs!SentTime = Now()
            rs!Processed = True
            rs.Update
        End If
        
 ---------------------------------
Code:
(2) 
 Function GenerateEmail(sTo As String, sCC As String, sSubject As String, sBodyText As String, Optional sAttachment As String = "") As Boolean
    Dim NewMessage As MailItem

    On Error GoTo Err_Handler
    
    Set NewMessage = Application.CreateItem(olMailItem)
    
    With NewMessage
        .SentOnBehalfOfName = "FarhanSyed@xxx.net"
        .To = sTo
        .CC = sCC
        .Subject = sSubject
        .BodyFormat = olFormatHTML
        .Body = sBodyText
        
        If sAttachment <> "" Then
            .Attachments.Add Source:=sAttachment
        End If
        
        .DeleteAfterSubmit = True
        .Send
        DoEvents
        
    End With
        
    Set NewMessage = Nothing
    GenerateEmail = True
    
Exit Function 
--------
Now we have some new recerds/reports using DAO recordset which have to use "Profile-2" for particular email address i.e. @xx. The profile has been setup and its working/open manually. but the problem is that when I opened the profile-1 its trying to send email of profile 2, its mentioned the profile-2 email can't be sent and I want avoid this message but don't know how.

I'm not its make sense to you or as English is not my first language.
Is there any way I can more interactive i.e chat/live online to convey my message as I have to do asap
Many thanks
Farhan
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Hi All
I have few functions in my Outlook (Mentioned Above), which sending reports to relevant users by using recordset DAO , every thing is working fine.
Now the problem is that , few reports I would like to send by using different profile lets say profile "Profile-B"

Firsly, The default profile is "Profile -A" , I was thinking if the specif reports come through DAO using Where or contry by using IF condition
i.e. reports =B Then I can call Profile-B"
Could you please suggest how can I do by using following Function(changing profile).
Or any other suggestions

Those above function written by some one who left but I have to mangae and I'm not very good in VBA/ADA or DAO but have general knowledge

Please Please help me on that.
Many thanks
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,351
Members
452,907
Latest member
Roland Deschain

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top