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
B Outlook 2019 Custom Email form - Edit default email form Outlook VBA and Custom Forms 5
F Add a category before "Send an Email When You Add an Appointment to Your Calendar" Outlook VBA and Custom Forms 0
T Problem when requesting to view an email in a browser Using Outlook 0
J Outlook 365 Forward Email Subject to my inbox when new email arrive in shared inbox Using Outlook 0
HarvMan Archive Email Manually Using Outlook 1
L Fetch, edit and forward an email with VBA outlook Outlook VBA and Custom Forms 2
S New Email "From" box stopped working Using Outlook 0
Rupert Dragwater Duplicate email in Folder Using Outlook 7
M "Attachment Detacher for Outlook" add in, does it update the server copy of the email? Using Outlook 1
W Outlook 365 I am getting the "Either there is no default mail client" error when I try to send an email on excel Office 365 Using Outlook 1
MattC Changing the font of an email with VBA Outlook VBA and Custom Forms 0
L Specific Incoming Email Address Immediately Deleted Using Outlook 2
Witzker Outlook 2019 Macro to send an Email Template from User Defined Contact Form Outlook VBA and Custom Forms 0
Witzker Outlook 2019 Edit contact from email does not open the user defined contactform Using Outlook 3
V Macro to mark email with a Category Outlook VBA and Custom Forms 4
R Roadrunner Email Settings | Contact Roadrunner Customer Support Outlook VBA and Custom Forms 1
D Gmail mail is being delivered to a different email inbox in Outlook App 2021 Using Outlook 2
Albert McCann Outlook 2021 Outlook Display of HTML Email from two senders is glitchy Using Outlook 0
A How Do I Setup My Optonline.Net Email Account? Outlook VBA and Custom Forms 1
H Preventing the 'email address fetch from Exchange' crashing email reading code Exchange Server Administration 0
D multiple email accounts - why do I have to choose the "from" account address?? Using Outlook 2
Wotme create email only data file Using Outlook 1
F Outlook 2016 Email with attachments not being received Using Outlook 3
J Outlook 2019 Regex email addresses from body Outlook VBA and Custom Forms 6
D Prompt to prefix subject line whenever sending an email Outlook VBA and Custom Forms 3

Similar threads

Top