Record eMail details in Outlook 2007

Status
Not open for further replies.
S

scrawny

Does anyone know how to grab certain information out of an email item

(such as subject, date of receipt, sender etc.).

I can capture this information on Application.NewMail... but to throw

a spanner in the works - I also want the folder name recorded as well

where the user places it.

For example, if a user has Folder 1, Folder 2, Folder 3 under their

Inbox... And as soon as a mail arrives to their inbox they read it and

then decide it needs to go to Folder 2... can I capture the emails

information with the chosen folder at this point?

Cheers,

Scrawny.
 
You can handle the ItemAdd() event on the Items collection of any folders

you want. Get the folder, get its Items collection, then subscribe to the

ItemAdd() event.

"scrawny" <scrawnyguns@gmail.com> wrote in message

news:5cd3581d-01b4-4f61-b921-b8d2d2c42da1@m7g2000prd.googlegroups.com...
> Does anyone know how to grab certain information out of an email item
> (such as subject, date of receipt, sender etc.).
> I can capture this information on Application.NewMail... but to throw
> a spanner in the works - I also want the folder name recorded as well
> where the user places it.

> For example, if a user has Folder 1, Folder 2, Folder 3 under their
> Inbox... And as soon as a mail arrives to their inbox they read it and
> then decide it needs to go to Folder 2... can I capture the emails
> information with the chosen folder at this point?

> Cheers,

> Scrawny.
 
Thanks for your reply... sorry if I'm a bit slow to catch on, but

where would I be going wrong in the following code:

Dim oApp As New Outlook.Application

Public WithEvents oFolder1 As Outlook.Folder

Public WithEvents oFolder2 As Outlook.Folder

Public WithEvents oFolder3 As Outlook.Folder

Private Sub Application_Startup()

Set oFolder1 = oApp.Session.GetDefaultFolder

(olFolderInbox).Folders.Item("Folder 1")

Set oFolder2 = oApp.Session.GetDefaultFolder

(olFolderInbox).Folders.Item("Folder 2")

Set oFolder3 = oApp.Session.GetDefaultFolder

(olFolderInbox).Folders.Item("Folder 3")

End Sub

Private Sub oFolder1_ItemAdd(ByVal Item As Object)

Dim oMail As Outlook.MailItem

Set oMail = Item

MsgBox oMail.Subject

End Sub

> ... Other Folder objects have the same portion of code as that last

ItemAdd sub.

At the moment I'm just returning the subject to a message box just for

test purposes.

Cheers,

Scrawny
 
What do you mean where are you going wrong, what's not working?

I see 2 things offhand, in Outlook VBA code you never, ever create a new

Outlook.Application object, you use the Application object that's handed to

you and which is trusted. Second, don't assume that what comes to a folder

is necessarily a mail item. It could be a post item, or in Inbox it could be

a task request, meeting request, etc. Use Item.Class to test for olMail to

see if it's really a mail item.

"scrawny" <scrawnyguns@gmail.com> wrote in message

news:620a9295-c407-4269-a369-3384885e28da@v15g2000prn.googlegroups.com...
> Thanks for your reply... sorry if I'm a bit slow to catch on, but
> where would I be going wrong in the following code:

> Dim oApp As New Outlook.Application
> Public WithEvents oFolder1 As Outlook.Folder
> Public WithEvents oFolder2 As Outlook.Folder
> Public WithEvents oFolder3 As Outlook.Folder

> Private Sub Application_Startup()
> Set oFolder1 = oApp.Session.GetDefaultFolder
> (olFolderInbox).Folders.Item("Folder 1")
> Set oFolder2 = oApp.Session.GetDefaultFolder
> (olFolderInbox).Folders.Item("Folder 2")
> Set oFolder3 = oApp.Session.GetDefaultFolder
> (olFolderInbox).Folders.Item("Folder 3")
> End Sub

> Private Sub oFolder1_ItemAdd(ByVal Item As Object)
> Dim oMail As Outlook.MailItem

> Set oMail = Item
> MsgBox oMail.Subject
> End Sub

> ... Other Folder objects have the same portion of code as that last
> ItemAdd sub.

> At the moment I'm just returning the subject to a message box just for
> test purposes.

> Cheers,

> Scrawny
 
No worries... that makes sense.

But how do I declare the folders which reside under the inbox?

Is that Set command in Application_Startup accurate or is there a

better way.

By the way, I am safely assuming that these folders have already been

set up.

The actual code above does allow the declarations of oFolder1, 2, 3...

but on nothing happens when I add a mail item to the folder. So it's

obviously not declaring the right folder. Or the variable isn't

pointing to the folder that I think it should be.

-Scrawny
 
If the folders don't exist then your return values for Folder1, etc. would

be null (Nothing). So you can test and create the folder if it doesn't

already exist:

Set oFolder1 =

oApp.Session.GetDefaultFolder(olFolderInbox).Folders.Item("Folder 1")

If oFolder1 Is Nothing Then

Set oFolder1 =

oApp.Session.GetDefaultFolder(olFolderInbox).Folders.Add("Folder 1",

olFolderInbox) 'watch for line wrap on this, it's all one line

End If

Step your code and make sure that you get valid Folder objects as the code

runs. You can also check the Items.Count property for each of those folders

to check the number of items in the folder.

Assuming the folders are valid the ItemAdd() event handlers look OK.

"scrawny" <scrawnyguns@gmail.com> wrote in message

news:af0a3a9f-ed41-482f-8933-46e95cbfe97f@y4g2000prf.googlegroups.com...
> No worries... that makes sense.

> But how do I declare the folders which reside under the inbox?
> Is that Set command in Application_Startup accurate or is there a
> better way.
> By the way, I am safely assuming that these folders have already been
> set up.

> The actual code above does allow the declarations of oFolder1, 2, 3...
> but on nothing happens when I add a mail item to the folder. So it's
> obviously not declaring the right folder. Or the variable isn't
> pointing to the folder that I think it should be.

> -Scrawny
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
N linking an already sent/rec'd email to contact record like it did in 2000 Using Outlook 0
S Editing an email with notes and saving it for record using Macro Outlook VBA and Custom Forms 3
D DB/Object/Record vs File/List/Range Terminology Outlook VBA and Custom Forms 0
A Record opened emails for reopening later Using Outlook 2
A Record opened emails for reopening later Outlook VBA and Custom Forms 16
B Track Record Activity Using Outlook 1
D Record Appointment to Calendar on "Public Folder" Outlook VBA and Custom Forms 13
B Customize contact record phone fields Using Outlook 2
B Macro to record what time it is Outlook VBA and Custom Forms 2
M convert/import a customized record into the default "Account" record BCM (Business Contact Manager) 0
P People/Contact Record gets deleted when I edit it? Using Outlook 3
U No scrolling in note field of contact record Using Outlook 1
R Can BCM monitor and select specific emails and use content info to update the client's record? BCM (Business Contact Manager) 1
M Predefined Outlook Fields not available to add into a BCM record BCM (Business Contact Manager) 0
J How to show the "value" of a user-defined Account field in a Contact Record BCM (Business Contact Manager) 2
J How to create fields that will use the same value on different record types BCM (Business Contact Manager) 2
A delete database --> record remnants ?? BCM (Business Contact Manager) 3
M BCM 2010 Link to Record (very) slow BCM (Business Contact Manager) 2
L Importing multiple record from .vcf (vCard) file Using Outlook 5
P Hyperlink to Access record/Form Outlook VBA and Custom Forms 2
H Re: record of sales for each contact BCM (Business Contact Manager) 1
A Is There An Easier Way to Access a Business Contact Record? BCM (Business Contact Manager) 2
A Programmatically duplicating BCM's "Link to Record" function BCM (Business Contact Manager) 2
C Outlook record the step I take getting to the user template? Outlook VBA and Custom Forms 1
R One Click business contact record creation - From an E Mail? BCM (Business Contact Manager) 1
Y How to record macros in Outlook2007? Outlook VBA and Custom Forms 1
T Why do Outlook Desktop 2021 tasks from my wife's email show up in my task pane? Using Outlook 2
A Opening a link from an email automatically Outlook VBA and Custom Forms 0
D Outlook 2021 New email reminder Using Outlook.com accounts in Outlook 0
Rupert Dragwater How do I remove an email ending with @gmail.com Using Outlook 4
M A plug in (or method) to keep email message formatting after it expires Using Outlook 1
L VBA to Triage Incoming Email Outlook VBA and Custom Forms 0
R Legacy Outlook on Mac Email Cache Using Outlook 0
P Email address auto-completes work fine on laptop, but no longer on desktop Using Outlook 3
S Create Outlook Task from Template and append Body with Email Body Outlook VBA and Custom Forms 4
H Copying email address(es) in body of email and pasting in To field Outlook VBA and Custom Forms 1
A Search folder and move the email Outlook VBA and Custom Forms 0
P VBA to add email address to Outlook 365 rule Outlook VBA and Custom Forms 0
farrissf Outlook 2016 Optimizing Email Searches in Outlook 2016: Seeking Insights on Quick Search vs Advanced Search Features Using Outlook 0
D Delete selected text in outgoing email body Outlook VBA and Custom Forms 0
F Graphics in email / Mac recipient garbled Using Outlook 0
D Outlook VBA forward the selected email to the original sender’s email ID (including the email used in TO, CC Field) from the email chain Outlook VBA and Custom Forms 2
Witzker Outlook 2019 Macro to seach in all contact Folders for marked Email Adress Outlook VBA and Custom Forms 1
E Outlook 365 Save Selected Email Message as .msg File - oMail.Delete not working when SEARCH Outlook VBA and Custom Forms 0
S Email Macros to go to a SHARED Outlook mailbox Draft folder...NOT my personal Outlook Draft folder Using Outlook 2
R Outlook 365 VBA AUTO SEND WITH DELAY FOR EACH EMAIL Outlook VBA and Custom Forms 0
G Print email attachments when hit subfolder Outlook VBA and Custom Forms 1
C Spam Email? Using Outlook 2
G Automatically delete email when a condition is met Outlook VBA and Custom Forms 1
E Save Selected Email Message as .msg File - digitally sign email doesn't works Outlook VBA and Custom Forms 1

Similar threads

Back
Top