Create a new field in Outlook?

R

Robby

Hello,

Is there any way to create/add a new field in MS Outlook. Basically I just
want to import a field that exists in one of my Access tables to Outlook.

All help appreciated!
 
K

Ken Slovak - [MVP - Outlook]

You can create what's called a UserProperty on items, but the export/import
function won't import custom properties. You would have to write your own
code to do that.
 
R

Robby

I am familiar with C/C++/Win32 programming. Is it very difficult to write my
own code to import a new field in Outlook from access ?


--
Best regards
Roberto


Ken Slovak - said:
You can create what's called a UserProperty on items, but the export/import
function won't import custom properties. You would have to write your own
code to do that.
 
K

Ken Slovak - [MVP - Outlook]

Outlook code is completely different than usual Win32 programming, you have
to know the Outlook object model and in this case the Access object model. I
don't do C++ so I couldn't help with that.

You can look at the information and tons of samples at www.outlookcode.com
for Access importing samples, but I'd guess they are all or almost all in
VBA/VB/C#/VB.NET code.
 
R

Robby

hello Ken,

I used to do alot of VBA.... 4 years ago. Unfortunately, its sort of
forgotten!

I simply need to map and import a new field from my Access tables. I was
hoping for a one or two line snippet sample of code in VBA coded in a macro.
From the little that I remember about VBA, I am sure it isn't that
complicated.

In one post a felow said to use:

MailItem.UserProperties

But how, what procedures.... do I create a macro in outlook and so forth ?

The only reason I wanted to do this is so I can bring in a feild from Access
to Outlook and then allow synchronization with a Blackberry.

If anyone can gracefully post a simple sample that allows Outlook to import
a new field, I would really appreciate it. :)


--
Best regards
Roberto


Ken Slovak - said:
Outlook code is completely different than usual Win32 programming, you have
to know the Outlook object model and in this case the Access object model. I
don't do C++ so I couldn't help with that.

You can look at the information and tons of samples at www.outlookcode.com
for Access importing samples, but I'd guess they are all or almost all in
VBA/VB/C#/VB.NET code.
 
K

Ken Slovak - [MVP - Outlook]

Well, it's hard to even supply a code snippet without know more about what
you want. For example is this for contact items or task or appointment items
or what? Is this for every item in a folder or selected items? Be more
detailed in describing your requirements.

At a very basic level assuming you have a macro (VBA Outlook Sub) that has a
ContactItem called oContact and you have an ADO recordset with the field you
want, one named "Foobar" that's a text field and you want to add that
property from the recordset to the oContact item, that would look like this:

' oRST is an ADOB.Recordset already instantiated and filled

Dim oProp As Outlook.UserProperty
Set oProp = oContact.UserProperties("Foobar")
If (oProp Is Nothing) Then
Set oProp = oContact.UserProperties.Add("Foobar", olText, True)
End If
oProp.Value = oRST.Fields("Foobar")
oContact.Save

Of course a DAO recordset would be slightly different, and that snippet
doesn't cover selecting the items to update, getting the recordset and so
on.
 
R

Robby

Hello Ken,

Thanks for replying!

Okay, I have a table called xxx which is created in an Access database
called LS. This table contains a field that does not exist in the contact
items of MS Outlook. The field is called "TBK_Comment". I would like to
import all the fields from this table including the TBK_Comment field. I
really don't need more that this, except that in the future I my require to
bring over several fields instead of one field.

So basically now, if I import the table from Access into MS Outook, I am
able to import all the fields except the one that does not exist in Outlook.

So my question to you is, If I use the snippet of code you suppiled:

==========================================
Dim oProp As Outlook.UserProperty
Set oProp = oContact.UserProperties("TBK_Comment")
If (oProp Is Nothing) Then
Set oProp = oContact.UserProperties.Add("TBK_Comment", olText, True)
End If
oProp.Value = oRST.Fields("TBK_Comment")
oContact.Save
============================================

will this import the TBK_Comment field only? Suppose I would like to import
all the fields including the TBK_Comment field?

Also, does this snippet of code have to be inserted in a VBA macro?
at Tools>Macro>Macros ?

Thanks for your help!

--
Best regards
Roberto


Ken Slovak - said:
Well, it's hard to even supply a code snippet without know more about what
you want. For example is this for contact items or task or appointment items
or what? Is this for every item in a folder or selected items? Be more
detailed in describing your requirements.

At a very basic level assuming you have a macro (VBA Outlook Sub) that has a
ContactItem called oContact and you have an ADO recordset with the field you
want, one named "Foobar" that's a text field and you want to add that
property from the recordset to the oContact item, that would look like this:

' oRST is an ADOB.Recordset already instantiated and filled

Dim oProp As Outlook.UserProperty
Set oProp = oContact.UserProperties("Foobar")
If (oProp Is Nothing) Then
Set oProp = oContact.UserProperties.Add("Foobar", olText, True)
End If
oProp.Value = oRST.Fields("Foobar")
oContact.Save

Of course a DAO recordset would be slightly different, and that snippet
doesn't cover selecting the items to update, getting the recordset and so
on.
 
K

Ken Slovak - [MVP - Outlook]

Again, the import dialog won't import custom fields. So if you get your
table from Access as a recordset you first have to get each matching
existing contact for each table row before you can get to the custom field.

If the contacts to be imported don't exist you can use the Access table to
create the contacts one by one.

The code I showed gets one field from a recordset and sets that field in a
previously selected contact. The code would be in a VBA macro.

Let's say the contacts exist already and they are in the default Contacts
folder, and that you already have your Access recordset with fields for your
custom property and also for name or other identifying characteristics. This
would get your entire collection of Contacts:

Dim oFolder As Outlook.MAPIFolder
Dim colItems As Outlook.Items
Dim oNS As Outlook.NameSpace

Set oNS = Application.GetNameSpace("MAPI")
Set oFolder = oNS.GetDefaultFolder(olFolderContacts)
Set colItems = oFolder.Items

Then you'd need code to look at each contact in the Items and try to match
it with a row in your recordset. For iterating the Outlook Items:

Dim oContact As Outlook.ContactItem
For Each oContact In colItems

You'd then search the recordset for a matching contact row and once you have
that you'd be able to use the code I originally showed.

If you have any distribution lists in your folder that would fire an error
when the DL was hit and you attempted to assign it to a ContactItem object
(oContact). So you'd also need code to allow for that. A simple On Error
Resume Next and a test for oContact Is Nothing would work as a prerequisite
to getting into the loop code.

You might want to look at the database code samples at www.outlookcode.com
for various samples of doing this sort of thing with Outlook code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top