Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need code for outlook interface 5

Status
Not open for further replies.

calahans

Programmer
Jun 14, 1999
348
0
0
IE
I need to get code to basically connect to an outlook users contacts in outlook and based on a name they input into a textbox retrieve the corresponding number from outlook. <br>
<br>
I know about the outlook object library and can connect to the current instance of outlook running, but I'm stumped at that point.<br>
<br>
Thanks
 
I don't have Outlook on my machine but if you can connect to the current copy does that mean you can use the VB Object Browser to see what is exposed by Outlook?<br>
<br>
Mike<br>
<p>Mike Lacey<br><a href=mailto:Mike_Lacey@Cargill.Com>Mike_Lacey@Cargill.Com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Yeah, I have used the object browser to expose the various properties/methods of the object but unfortunatley the machine I'm using now has no help files included (major pain). I can't get the CD for a few days so I need code from someone else, if possible.<br>
<br>
Thanks
 
create new form and add text boxes<br>
ComTo, ComCc, ComBcc, mBody, mSubject <br>
Then add a command button CmdSend<br>
<br>
Private Sub CmdSend_Click()<br>
<br>
Dim olapp As Object<br>
Dim oitem As Object<br>
<br>
Set olapp = CreateObject(&quot;Outlook.Application&quot;)<br>
Set oitem = olapp.CreateItem(0)<br>
With oitem<br>
.Subject = mSubject<br>
.To = ComTo.Text & &quot;;&quot;<br>
.Body = mBody<br>
If ComCc.Text &lt;&gt; &quot;&quot; Then<br>
.cc = ComCc.Text & &quot;;&quot;<br>
End If<br>
If ComBcc.Text &lt;&gt; &quot;&quot; Then<br>
.bcc = ComBcc.Text & &quot;;&quot;<br>
End If<br>
.Send<br>
End With<br>
Set olapp = Nothing<br>
Set oitem = Nothing<br>
<br>
Unload Me<br>
end sub
 
Thanks, but I have code to send a message using outlook. If you read my original post I'm looking to get at the contacts part of outlook.<br>
<br>
Any code?
 
the contacts are stored in a file called *.pst<br>
Depending on if you are running '98 or NT its loaction on your C:\drive will be different.<br>
<br>
Which version of Outlook do you have?<br>
<br>
'98 you need at patch from Microsoft which will allow you to access that file.<br>
if you have outlook '97 upgrade it to 2000<br>
'2000 you don't need the patch<br>
Also you can call Microsoft at (425) 635-7031 for free Outlook Help<br>
<br>
Now in Access '97 and '2000 you can attach the file as a link and view the any folder in Outlook including Contacts.<br>
<br>
Here is some more info:<br>
------------------<A HREF=" TARGET="_new"><br>
Before you can use DAO to gain access to Microsoft Exchange Client or Outlook data, you must install the Microsoft Jet Exchange installable ISAM. Although you can install the Microsoft Jet Exchange installable ISAM using the Dataacc.exe file that is included in the Microsoft Office 97 Value Pack, that version of the driver does not register itself and has certain limitations. To install the most current version of the driver, download and run Wzmapi80.exe to install the Microsoft Exchange and Outlook Wizard. This installs and registers the most current version of Msexch35.dll so you can use it from DAO, and also installs the Microsoft Exchange and Outlook Wizard so you can import and link Microsoft Exchange and Outlook data using the Microsoft Access user interface.<br>
<br>
find Wzmapi80.exe at:<br>
<A HREF=" TARGET="_new">------------------<br>
Have fun
 
Thanks Doug - I won't get near this until next week but this looks like an excellent starting point.<br>
<br>
C
 
Really what you need to do is study up on the methods exposed in Outlook and learn about the terminology. I've just provided this in another post but will include it here also.

Steve King


Public Function GetContact(strName As String)

On Error Resume Next

Dim oApp As Outlook.Application
Dim myNameSpace As NameSpace
Dim myAddressLists As AddressLists
Dim myAddressList As AddressList
Dim myAddrEntries As AddressEntries
Dim myEntry As AddressEntry
Dim intNameLen As Integer
Dim intCnt As Integer
Dim intCnt2 As Integer
Dim strUser As String
Dim strTempAddr As String

Set oApp = GetOutlook()
Set myNameSpace = oApp.GetNamespace(&quot;MAPI&quot;)
intNameLen = Len(strName)

For Each myAddressList In myNameSpace.AddressLists
If myAddressList.Name = &quot;Contacts&quot; _
Or myAddressList.Name = &quot;Personal Address Book&quot; Then
For Each myEntry In myAddressList.AddressEntries
If InStr(1, myEntry.Name, strName) Then
strTempAddr = myEntry.Address
If InStr(1, strTempAddr, &quot;=&quot;) Then
strTempAddr = GetShortAddr(myEntry.Members(intCnt).Address)
End If

' Details pops up the properties dialog
'myEntry.Details (0)
'Debug.Print myEntry.Name & &quot; (&quot; & myEntry.Address & &quot;)&quot;
'If myEntry.DisplayType
strUser = myEntry.Name & &quot; (&quot; & strTempAddr & &quot;)&quot;
strTempAddr = &quot;&quot;
Select Case myEntry.DisplayType
Case olDistList, olPrivateDistList '4, 5
Debug.Print &quot; Distribution List: &quot; & strUser
For intCnt = 1 To myEntry.Members.Count
strTempAddr = myEntry.Members(intCnt).Address
If InStr(1, strTempAddr, &quot;=&quot;) Then
strTempAddr = GetShortAddr(myEntry.Members(intCnt).Address)
End If
Debug.Print &quot; Member: &quot; & myEntry.Members(intCnt).Name _
& &quot; (&quot; & strTempAddr & &quot;)&quot;
strTempAddr = &quot;&quot;
Next intCnt
Case olRemoteUser '6
Debug.Print &quot; Remote User: &quot; & strUser

Case olUser '0
Debug.Print &quot; User: &quot; & strUser
Case Else
Debug.Print &quot; Unknown &quot; & strUser
End Select
End If
Next myEntry
End If
Next myAddressList

End Function


Public Function GetOutlook() As Outlook.Application

Dim MyOutlook As Outlook.Application ' Variable to hold reference
Dim OutlookWasNotRunning As Boolean ' Flag for final release.

On Error Resume Next ' Defer error trapping.
Set MyOutlook = GetObject(, &quot;Outlook.Application&quot;)
If Err.Number <> 0 Then OutlookWasNotRunning = True
Err.Clear ' Clear Err object in case error occurred.

If OutlookWasNotRunning = True Then
MyOutlook.Application.Quit
End If

Set GetOutlook = MyOutlook.Application
Set MyOutlook = Nothing ' Release reference

End Function Professional growth follows a healthy professional curiosity
 
Are there similar code approaches for Outlook Express? I need to capture all email messages for the last year into a Access (Jet) database. I need to put To, From, Subject, CC, Date stamp, and the message into an Access database.

Suggestions and sample code much appreciated. I have good VB/DAO skills but have never used anything associated with Outlook/ Outlook Express.

 
Just check out the MAPI help in the VS Help files...that should get you a good start
 
I tried the code from scking, but all I get is 'undefined type in
'Public Function GetOutlook() 'As Outlook.Application'

THe problem with code snippets is figuring out what's what.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top