?
Solved

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

Posted on 2008-10-09
15
Medium Priority
?
281 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 3
  • 3
15 Comments
 
LVL 2

Expert Comment

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

0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 22682975
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 34

Author Comment

by:Mike Eghtebas
ID: 22683034
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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 2

Expert Comment

by:doublebug
ID: 22683136
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 34

Author Comment

by:Mike Eghtebas
ID: 22683233
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 800 total points
ID: 22683371

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 34

Author Comment

by:Mike Eghtebas
ID: 22683392
Thank you for the response.

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

Mike
0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 1200 total points
ID: 22684436
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 34

Author Comment

by:Mike Eghtebas
ID: 22687781
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
ID: 22687902
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 34

Author Comment

by:Mike Eghtebas
ID: 22688208
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 34

Author Comment

by:Mike Eghtebas
ID: 22688284
I will have a follow-up question for chkPause.

Mike
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 22688306
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 34

Author Comment

by:Mike Eghtebas
ID: 22688350
0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 22688400
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

770 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