paste/modify the "To:" of an already open e-mail

Asghaar

Registered User.
Local time
Today, 02:06
Joined
Jul 4, 2012
Messages
47
Hello all,

I need your help in accomplishing the following thing:

- i want to be able to paste a recordset in an existing(opened e-mail)

Right now i have some code that accplishes a part of this - i paste the recordset to the "To:" of an e-mail that is created.
I want to open an e-mail (have it in reply mode) and the code paste my recordset to this already opened e-mail and not creating a new outlook message with the to and cc mentioned by the record set.
Find below the code that I have right now ( working,tested):

Code:
Dim objOutlook As Object    'Outlook.Application  (Note dimensioned as Object)
    Dim objEmail As Object      'Outlook.MailItem     (Note dimensioned as Object)
    Dim objNameSpace As Object  'Outlook.NameSpace    (Note dimensioned as Object)
    Const olMailItem As Long = 0    'For Late Binding
    Const olFolderInbox As Long = 6 'For Late Binding
    Const olFormatHTML As Long = 2  'For Late Binding
       
    On Error Resume Next
    Set objOutlook = GetObject(, "Outlook.Application")
    On Error GoTo 0     'Resume error trapping ASAP
   
    If objOutlook Is Nothing Then
        Set objOutlook = CreateObject("Outlook.Application")
        Set objNameSpace = objOutlook.GetNamespace("MAPI")
        objNameSpace.GetDefaultFolder(olFolderInbox).Display
    End If
   
    Set objEmail = objOutlook.CreateItem(olMailItem)
 
 
 With objEmail
        .To = Email
        .CC = "me;" & ccmail
        .Subject = " "
        .Display
     
End With

Thank you all for your help and replies.


Ps: the recordset part if someone is interested :
Dim Email As String
Dim ccmail As String
'Email = Me!Text34

Dim rst As DAO.Recordset
Dim rst2 As DAO.Recordset
Dim db As DAO.Database
Dim strString As String
Dim strString2 As String

Set db = CurrentDb

Set rst = db.OpenRecordset("SELECT mail FROM t1;")
Set rst2 = db.OpenRecordset("SELECT e_mail FROM t2;")

With rst
Do Until .EOF
strString = strString & ![mail]
.MoveNext
Loop
End With

With rst2
Do Until .EOF
strString2 = strString2 & ![e_mail]
.MoveNext
Loop
End With

Email = strString
ccmail = strString2
rst.Close
 
Am sorry but I do not get it.. What is working OR what is not working here?
 
Am sorry but I do not get it.. What is working OR what is not working here?


Hello,

The above code is working fine - the problem is that it creates a new e-mail in outlook where it paste the recordset.
I want the recordset to be pasted in an e-mail that i have open in the taskbar.
For example: i recive an e-mail ,i hit reply and after if i hit the form button - i want it to "paste" my recordset the e-mail i just opend with the reply button from outlook.

I hope i managed to clarify things a little.

Regards,
 
No ideas how i could make my from thru VBA to past my recordset to the To or CC of an e-mail already opened in taskbar ?

Right now i'm able to copy my recordset only to a new e-mail that i create thru VBA ( Set objOutlook = CreateObject("Outlook.Application")).

Hope someone will know how to help me.

Thank you in advance to all the replies.
 
Hello Asghaar,

Sorry for not getting back, might have unsubscribed from this thread.. I missed my email notifications :confused:

Well I am not sure that is possible, as far as I know.. but someone might actually know a way to do it.. I am sorry if I am not of much help here. :(
 
Hello all,

Meanwhile i managed to find a solution to obtain exact what i was looking for ( using recordset and ActiveInspector ).
Please find below the code for anyone that will find it usefull:

Code:
Private Sub Command93_Click()


On Error GoTo Err_Command93_Click

Dim Email As String
Dim ccmail As String
'Email = Me!Text34

Dim rst As DAO.Recordset
Dim rst2 As DAO.Recordset
Dim db As DAO.Database
Dim strString As String
Dim strString2 As String
 
Set db = CurrentDb
 
Set rst = db.OpenRecordset("SELECT mail FROM t1;")
Set rst2 = db.OpenRecordset("SELECT e_mail FROM t2;")
 
With rst
Do Until .EOF
  strString = strString & ![mail]
  .MoveNext
Loop
End With

With rst2
Do Until .EOF
  strString2 = strString2 & ![e_mail]
  .MoveNext
Loop
End With

Email = strString
ccmail = strString2
rst.Close

    'NOTE: Additional Const declaration
Dim myEmail As Object
Dim objOutlook As Object

Set objOutlook = CreateObject("Outlook.Application")
Set myEmail = objOutlook.ActiveInspector

'Dim myEmail As Inspector
Dim objEmail As Object
'Dim strName As String
''Search for open mail
'Set myEmail = Outlook.Application.ActiveInspector
If Not TypeName(myEmail) = "Nothing" Then
Set objEmail = myEmail.currentItem

Else
MsgBox "No open mail has been detected" & Chr(13) & _
"If you wish to add an email, you will have " & Chr(13) & _
"to open the mail.", vbOKOnly, "No open mail detected"
End If

With objEmail
        string1 = .To
        STRING2 = .CC
        .To = string1 & ";" & "   " & Email
        .CC = STRING2 & " ; " & "whatever" & ccmail
        '.Subject = " "
        '.save
        .Display
        '.Send
End With


Exit_Command93_Click:
    Exit Sub

Err_Command93_Click:
    'MsgBox Err.Description
    Resume Exit_Command93_Click



End Sub
 

Users who are viewing this thread

Back
Top Bottom