Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-04-13
4
Medium Priority
?
456 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses

609 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