Solved

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

Posted on 2004-04-13
4
443 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
  • 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 250 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

770 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