Solved

Adding Entry to Outlook Address Book

Posted on 2000-04-12
2
224 Views
Last Modified: 2010-05-02
I'm trying to add an address entry to the outlook address book.  I found this code in another section but can't get it to work even after adding MAPI components and referencing outlook.

Here's the code:
Function AddEntry()
 
Dim objSession As MAPI.Session   ' Session object
Dim objMyPAB As AddressList      ' personal address book object
Dim objNewEntry As AddressEntry  ' new address entry object
Dim propTag As Long              ' MAPI property tag for new field
 
On Error GoTo error_olemsg
Set objSession = CreateObject("MAPI.Session")
 
' log on to session, supplying username and password
objSession.Logon 'profileName:="MyProfile", _

                 'profilePassword:="my_password"
 
' get PAB AddressList from AddressLists collection of Session
Set objMyPAB = objSession.AddressLists("Personal Address Book")
If objMyPAB Is Nothing Then
    MsgBox "Invalid PAB from session"
    Exit Function
End If
 
' add new AddressEntry to AddressEntries collection of AddressList
Set objNewEntry = objMyPAB.AddressEntries.Add "SMTP", "Jane Doe"
objNewEntry.address = "janed@exchange.microsoft.com"

 
' set MAPI property in new AddressEntry (don’t need to Add it)
propTag = &H3A08001E ' VB4.0: ActMsgPR_BUSINESS_TELEPHONE_NUMBER
objNewEntry.Fields(propTag) = “+1-206-555-9901”
 
' add custom property to new AddressEntry and set its value
objNewEntry.Fields.Add “CellularPhone”, vbString
objNewEntry.Fields(“CellularPhone”) = “+1-206-555-9902”
 
' commit new entry, properties, fields, and values to PAB AddressList
objNewEntry.Update
MsgBox “New address book entry successfully added”

Exit Function
 
error_olemsg:
MsgBox "Error " & Str(Err) & ": " & Error$(Err)
Exit Function ' so many steps to succeed; just exit on error
 
End Function




I've put it all in a module and call the procedure - I keep getting this error: user defined type not defined ... on this line....

dim objSession As MAPI.Session
0
Comment
Question by:basica
  • 2
2 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 2709065
perhaps this code will give you some ideas
0
 
LVL 28

Accepted Solution

by:
AzraSound earned 30 total points
ID: 2709067
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

867 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now