?
Solved

Help with ADO (not .NET) code for adding contact to MAPI folder

Posted on 2004-04-13
4
Medium Priority
?
452 Views
Last Modified: 2013-12-25
I can't get the following subroutine to work. It's meant to add a contact to a MAPI public folder. Can anyone tell me where I'm going wrong? It returns the error message: "Run-time error ‘-2147217895 (80040e19)’: Object or data matching the name, range, or selection criteria was not found within the scope of this operation." when it tries to open the record.

Also, can you please explain why the first version of strUrlFolder (commented out) doesn't work?

Thanks

---------------------------------------------------

Sub ADO_AddContactToMAPIFolder()
    Dim strUrlFolder As String
   
    'strUrlFolder = "http://server1/exchange/grandmas.org.uk/public folders/all public folders/dublin contacts/Peter Neely.eml"
    strUrlFolder = "file://./backofficestorage/grandmas.org.uk/public folders/all public folders/dublin contacts/Peter Neely.eml"

    With New ADODB.Record
        .Open strUrlFolder, , , adCreateOverwrite
        .Fields("DAV:contentclass") = "urn:content-classes:person"
        .Fields("urn:schemas:contacts:givenName") = "Peter"
        .Fields("urn:schemas:contacts:sn") = "Neely"
        .Fields("http://schemas.microsoft.com/exchange/outlookmessageclass") = "ipm.contact"
        .Fields.Update
    End With
End Sub
0
Comment
Question by:PNeely
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 10835484
this is NOT how you make use of an ADO recordset:

    With New ADODB.Record
        .Open strUrlFolder, , , adCreateOverwrite
        .Fields("DAV:contentclass") = "urn:content-classes:person"
        .Fields("urn:schemas:contacts:givenName") = "Peter"
        .Fields("urn:schemas:contacts:sn") = "Neely"
        .Fields("http://schemas.microsoft.com/exchange/outlookmessageclass") = "ipm.contact"
        .Fields.Update
    End With


for one thing, a Recordset MUST be associated with a Connection , which in turn has an associated ConnectionString.

You appear to not understand what ADO recordsets are about.

You cannot use ADO to send email messages, which is what you appear to be attempting here.

AW
0
 

Author Comment

by:PNeely
ID: 10842673
Thanks Arthur. You're right -- I'm new to all things ADO and probably don't understand recordsets properly -- which is why I'm posting here.

I copied the above lines of code from a book I've been reading about ADO and Exchange, but I seem to have got something wrong.

Can anyone help put their finger on it?

Thanks
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 10846969
First, you need an ADODB.Connection Object, and I have no clue as to how to create that to connect to Outlook.  I was not weven aware that ADO could be used in connection (pardon the pub, ooh, AM I bad!!!), with Outlook.

If you have a book, then you must be missing some details, becuase this code looks VERY suspect.

AW
0
 

Accepted Solution

by:
DaveKane earned 1000 total points
ID: 10894842
Actually, using the Exchange OLEDB provider you do not need to instantiate a connection object to open an ADODB.Record (as apposed to a recordset). You can open a Record simply by specifying a valid URL, assuming that your account has the required permissions in that folder to perform that operation. So that code should work for Exchange 2000/2003, but your account may lack permissions.

As for the commented out URL, an HTTP-style URL for a public folder should point to the "public" virtual directory. If "dublin contacts" is just below All Public Folders in the public folder hierarchy it would look like this:

strUrlFolder = "http://<server_alias>/public/dublin contacts/Peter Neely.eml"
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

777 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