Opening a Contact Item from VB.Net

G

Guest

Hello and Thanks for the Help in Advance

I am trying to open a contact item using a button on a VB.Net toolbar. This was pretty straight foward in VB6 but I am having trouble getting to the Public Folder where the contacts are stored

Any Help would be apprecaited!!

Here is the code I have. I am getting the Contact name from a sql server.

Dim conSql As New SqlClient.SqlConnectio
conSql.ConnectionString = "Integrated Security = True;" &
"Data Source = *****;Initial Catalog = *****;
Dim cmd As New SqlClient.SqlComman
cmd.Connection = conSq
cmd.CommandType = CommandType.Tex
cmd.CommandText = "Select TWCUSTOM.dbo.fn_TW_GetContractor()
conSql.Open(
Dim ContractorName = cmd.ExecuteScalar(
conSql.Close(
' Set the application objec
Dim ol As Outlook.Applicatio
Dim oNS As Outlook.NameSpac
oNS = ol.GetNamespace("MAPI"
' Set the namespace objec
Dim myFolder As Outlook.MAPIFolde
Dim myFolder1 As Outlook.MAPIFolder = oNS.Session.Folders("Public Folders"
Dim myFolder2 As Outlook.MAPIFolder = myFolder1.Folders("All Public Folders"
Dim MyFolder3 As Outlook.MAPIFolder = myFolder2.Folders("Public Contacts"
Dim MyItems = MyFolder3.Item
Dim MYClause = "[CompanyName] =" & ContractorName & " And [Full Name] =" & "'" & ContractorName & "'
Dim MyContactsItems = MyItems.Restrict(MYClause
For Each MyItems In MyContactsItem
MyItems.Display(
Nex
 
W

Wei-Dong XU [MSFT]

Hi,

I'd suggest you can add some logon code. You will need to logon into outlook with one profile and then retrieve the information. Please see my
sample:
'---------------------------------------------------------------
'...
'logon with the default profile
ol = New outlook.Application
ons = ol.GetNamespace("MAPI")
ons.Logon("Default Outlook Profile")
'...
'logoff
ons.logoff()
ol .Quit()
...
'---------------------------------------------------------------

Please feel free to let me know if you have any further questions.

Best Regards,
Wei-Dong Xu
Microsoft Product Support Services
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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