Solved

Open email from Access in Reply or Forward Mode...

Posted on 2008-10-09
15
272 Views
Last Modified: 2012-05-05
From Access 2003, using:

SearchForItem strEntryID

I am able to open a specific email in Outlook.

Question: How can I revise the attached code to open the email identified by "strEntryID" in reply or forward mode?

Call SearchForItem (strEntryID, "Reply")

or

Call SearchForItem (strEntryID, "Forward")

Thank you.
Public Sub SearchForItem(strEntryID As String)

    Dim obj_CurrentOlkFolder As Outlook.MAPIFolder

    Dim olkApp As Object, _

        olkNS As Object, _

        OlkFolder As Object, _

        olkItem As Object, _

        strQuery As String

    Set olkApp = GetObject(, "Outlook.Application")

    Set olkNS = olkApp.Session

    Set olkItem = olkNS.GetItemFromID(strEntryID)

    If TypeName(olkItem) = "nothing" Then

            MsgBox "No match found"

    Else

            olkItem.Display

    End If

    Set OlkFolder = Nothing

    Set olkNS = Nothing

    Set olkApp = Nothing

End Sub

Open in new window

0
Comment
Question by:Mike Eghtebas
  • 9
  • 3
  • 3
15 Comments
 
LVL 2

Expert Comment

by:doublebug
Comment Utility
Can you explain a bit more .
What means in Reply or Forward mode?

0
 
LVL 33

Author Comment

by:Mike Eghtebas
Comment Utility
SearchForItem strEntryID

opens the email. Then, in Outlook, I have to click on Reply or Forward to prepared the email to be replied or forwarded. At this point I add the necessary messages and click on Send button to completed the process.

The automation I am looking is to avoid clicking on Reply or Forard in Outlook.

Thanks,

Mike
0
 
LVL 33

Author Comment

by:Mike Eghtebas
Comment Utility
re:> The automation I am looking is to avoid clicking on Reply or Forward in Outlook.

In access some other processes Identify which email has to be replied to and which one needs to be forwarded. In conjunction with each EntryID a flag "Reply" or "Forward" is specified.

So,  

Call SearchForItem (strEntryID, strReplyOrForwardFlag)

should do the job.

I want to automate this part because, eventually the whole process will be automated and hundreds of emails will be handled automatically by access alone with a click of button.

I know there are some security issues concerning Outlook. For now, I am taking one step at a time.

Mike
0
 
LVL 2

Expert Comment

by:doublebug
Comment Utility
ok.
Now it's clear. It's possible to use command bars and simulate click on reply button.

When you opene email a new Inspector is create. You can locate it using Application.Inspectors
collection. Every inspectos has CurrentItem property. That is emal being edited or shown.
Inspector also has CommandBars property. CommandBars has method FindControl.
You can find ID of the Reply and Forward buttons using OutlookSpy utility.
When you got CommandBarButton via FindControl you can execute it using Execute method.
354 is id of reply button.

So
After you find right inspector you need something like this.

Inspector.CommandBars.FindControl (vtMissing, 354).Execute

To find Inspector obtain EntryID of CurrentItem and compare with target EntryID using
Session.CompareEntryIDs method.

Use OutlookSpy to explore Outlook Object Model and there you can create your test scripts not leaving outlook UI.

It is very usefull.
0
 
LVL 33

Author Comment

by:Mike Eghtebas
Comment Utility
doublebug,

Sorry to say that I am not theat familar with Outlook working to translate your wonderfull instruction to code I can use.

1- What is a good book or resouce I can start reading and get familar with Outlook?

2- What will be the code (revising the submited solution) to handle this?

Thank you,

Mike
0
 
LVL 2

Assisted Solution

by:doublebug
doublebug earned 200 total points
Comment Utility

1. Look at http://outlookcode.com/. There are a lot of information and book references.
Plus there is forum.

As for second i mostly do coding in C++
Some corrections
To execute Reply
Inspector.CommandBars.FindControl(1, 354).Execute
To forward
Inspector.CommandBars.FindControl(1, 356).Execute

Some sample

Entry = "00000000038BAD41614F7D4E928566C15E148424A4062000"
Set Inspectors = Application.Inspectors
Set Session = Application.Session
Set TargetInspector = nothing

for each Inspector in Inspectors
    If Session.CompareEntryIDs(Entry, Inspector.CurrentItem.EntryID) then
        Set TargetInspector = Inspector
        Exit For
    end if
next

If TypeName(TargetInspector) <> "nothing" Then
   TargetInspector.CommandBars.FindControl(1, 354).Execute
End If


0
 
LVL 33

Author Comment

by:Mike Eghtebas
Comment Utility
Thank you for the response.

I will try it tomorrow when I come back to the office.

Mike
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 300 total points
Comment Utility
Something like?

Chris
Public Sub SearchForItem(strEntryID As String, Optional reply As Boolean, Optional forward As Boolean)

    Dim obj_CurrentOlkFolder As Outlook.MAPIFolder

    Dim olkApp As Object, _

        olkNS As Object, _

        OlkFolder As Object, _

        olkItem As Object, _

        strQuery As String, _

        mai As mailitem

    If reply = True And forward = True Then Exit Sub

    Set olkApp = GetObject(, "Outlook.Application")

    Set olkNS = olkApp.Session

    Set olkItem = olkNS.GetItemFromID(strEntryID)

    If olkItem.Class = olMail Then

        Set mai = olkItem

        If reply Then

            mai.reply

            mai.Body = mai.Body & vbCrLf & vbCrLf & "My text"

            mai.Send

        ElseIf mai.forward Then

            mai.forward

            mai.To = "fred@fred.com"

            mai.Send

        End If

    End If

    Set OlkFolder = Nothing

    Set olkNS = Nothing

    Set olkApp = Nothing

End Sub

Open in new window

0
 
LVL 33

Author Comment

by:Mike Eghtebas
Comment Utility
Chris,

Your code was easy for me to follow. I am sure the code from doublebug is great but need more effort to incorporate with my solution.

I changed your code to:

Public Sub SearchForItem(strEntryID As String, strMode As String)
.     "Reply", "Forward", "Open"-----------------------^
.

These flags will pass to this routine; is the revised portion capable of doing the job?

.
.
    If olkItem.Class = olMail Then
        Set mai = olkItem
        If strMode = "Reply" Then
            mai.reply
            mai.Body = mai.Body & vbCrLf & vbCrLf & "My text"
            mai.Send
        ElseIf strMode = "Froward" Then
            mai.forward
            mai.To = "MEghtebas@Company.com"
            mai.Send
        Else   'strMode = "Open" Then
            olkItem.Display
        End If
    End If
.
.


Thanks,

Mike
0
 
LVL 59

Expert Comment

by:Chris Bottomley
Comment Utility
Yes ... as long as you are not serious about using "strMode = "Froward" in teh body ;) and 'forward in the sub call.  The other concern is then that the case of the sent string is critical.

Chris
0
 
LVL 33

Author Comment

by:Mike Eghtebas
Comment Utility
In Reply or Forward mode (for now), I want it to wait for the user to add some additional comments. I know there is a boolean flag needs to be added to:

mai.Send

In some othe application, I have a check box (Me!chkPause) which determines whether there will be a pause or Outlook will send the email without any pause.

How can I incorporate

Me!chkPause

with

mai.Send

Thank you,

Mike


DoCmd.SendObject acSendReport, "rErrors_1", acFormatRTF, "SK@Company.com", , strSubject, strMsg, Me!chkPause

Open in new window

0
 
LVL 33

Author Comment

by:Mike Eghtebas
Comment Utility
I will have a follow-up question for chkPause.

Mike
0
 
LVL 59

Expert Comment

by:Chris Bottomley
Comment Utility
Not to directly answer the question but why not use a simple textbox in a loop checking for non null?

Dim strIn As String
Do While strIn = ""
    strIn = InputBox("Enter a datum", "Wait until non blank")
Loop
MsgBox strIn, , "Title Bit"

Chris
0
 
LVL 33

Author Comment

by:Mike Eghtebas
Comment Utility
0
 
LVL 33

Author Comment

by:Mike Eghtebas
Comment Utility
re:> Not to directly answer the question but why not use a simple textbox in a loop checking for non null?

From this response, I see that I have not been able to describe my question correctly.

Your code works okay. But it forwards and repllies to the email as soon as the code is executed. I want it to open the email in reply or forward mode  and wait the user click on the send button itself.

Or, maybe I need your last response again to understand it better. You may want to continue the discussion at link provided.

Thanks,

Mike
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Find out how to use dynamic social media in email signatures with this top 10 DOs & DON’Ts.
Check out this infographic on what you need to make a good email signature that will work perfectly for your organization.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now