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.
 
K

Ken Slovak - [MVP - Outlook]

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.
 
S

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
 
K

Ken Slovak - [MVP - Outlook]

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
 
S

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
 
K

Ken Slovak - [MVP - Outlook]

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
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
H Search Email Header for Content Type Outlook VBA and Custom Forms 1
A VBA Script - Print Date between first email in Category X and last email in Category Y Outlook VBA and Custom Forms 3
P Sending email from outlook IMAP to GMAIL where embedded images are added as attachment Using Outlook 1
D auto forward base on email address in body email Outlook VBA and Custom Forms 0
P How did hacker cause link to delete and archive containing email? Using Outlook 6
I 'quote marks' around email name Using Outlook 1
N contact list seen in Contact folder but knot in Address book or when 'TO' button is clicked in new email Using Outlook 0
T Junk Email does not get added to the Blocked Sender List Using Outlook 0
P i-Phone 6s Plus receiving 2 notifications from Outlook email Using Outlook 1
C WARNING - DO NOT USE AN OUTLOOK.COM ADDRESS FOR GOOGLE ACCOUNT RECOVERY EMAIL Using Outlook 10
T Why is every new email pinned (to keep it on top)? Windows 10 Using Outlook 6
M Outlook, send to > mail recipient - results in plain text email Using Outlook 1
P Can I create a Rule that sends me an email when I get a Task? Using Outlook 3
M Issue transferring Outlook 2016 email accounts & settings onto new computer Using Outlook 8
R Auto Assign Category colours to Incoming Emails based on whom the email is addressed Outlook VBA and Custom Forms 3
S Outlook email to configure setup for each mail Outlook VBA and Custom Forms 1
S Macro to extract email addresses of recipients in current drafted email and put into clipboard Outlook VBA and Custom Forms 2
A Is there an ID field you can use to pair a reply to the sent email? Outlook VBA and Custom Forms 4
C Auto Run VBA Code on new email Outlook VBA and Custom Forms 1
M How create a Rule to filter sender's email with more that one @ sign Using Outlook 1
A Prepending Email Addrs with "Display Name <email>" Has Stopped Working Using Outlook 0
Bering Forward selected email without the original email appended Outlook VBA and Custom Forms 0
Aussie Rules Run a Script on an Incoming Email OK and then the Email reverts Outlook VBA and Custom Forms 0
W Reply to email Using Outlook 4
F Junk Email does not get added to the Blocked Sender List Using Outlook 4

Similar threads

Top