Automation with Outlook

K

Kevin

I am trying to setup a connection to Outlook. I need to
gain access to the contacts database and I want be able
to setup alerts etc. based on information in the contacts
database. I am looking at the Access 97 Developers
Handbook and have the code shown below from that book.
When I run this code (from the CD which comes with the
book I get the following error:

Run-Time error '-1975254767(8a440111)':
The server is not available. Contact your Administrator
if this condition persists.

I need to qualify one more thing: I am using Access 2003
and Outlook 2003 as well. I am not sure if this is
happening because of differences in Outlook versions or
even in access and VBA.

Watch word wraps, not mine!

Private Sub cmdLoad_Click()
Dim objOLNamespace As Outlook.NameSpace
Dim objOLJournal As Outlook.MAPIFolder
Dim objFilteredItems As Outlook.Items
Dim outItem As Object
Dim frmStatus As Form
Dim lngItems As Long
Dim cItem As Long

Dim dbThis As Database
Dim rstJournal As Recordset

' Get tha MAPI Namespace
Set objOLNamespace = adhGetOutlook()

' Make sure we have a valid reference
If objOLNamespace Is Nothing Then
MsgBox "Error connecting to Outlook.",
vbExclamation
Else

' Open status form
DoCmd.OpenForm "frmLoadStatus"
Set frmStatus = Forms("frmLoadStatus")

' Turn on hourglass
DoCmd.Hourglass True

' Get reference to database, delete entries
' from journal table, and open a recordset on it
Set dbThis = CurrentDb
dbThis.Execute "DELETE * FROM tblJournalEntries"
Set rstJournal = dbThis.OpenRecordset _
("tblJournalEntries", dbOpenDynaset)

' Get a reference to the "Journal" folder
Set objOLJournal = objOLNamespace. _
GetDefaultFolder(olFolderJournal)

' Filter the items in the folder
Set objFilteredItems = _
adhFilterItems(objOLJournal.Items)

' Process the items in the folder, adding them
' to the journal entries table
With rstJournal
lngItems = objFilteredItems.Count

For Each outItem In objFilteredItems
.AddNew
!EntryID = outItem.EntryID
!Type = outItem.Type
!Subject = outItem.Subject
!Start = outItem.Start
!End = outItem.End
.Update

' Update the status form
cItem = cItem + 1
frmStatus.PercentDone = (cItem / lngItems)
frmStatus.Message = "Loaded item " & _
cItem & " of " & lngItems

' See if the Cancel button was pressed
DoEvents
If frmStatus.Cancelled Then
Exit For
End If
Next

' Clean up and give feed back
.Close
DoCmd.Close acForm, "frmLoadStatus"
MsgBox cItem & " journal entries loaded.", _
vbInformation

' If we loaded entries refresh the list
If cItem Then
With Me!cboTypes
.Requery
.Value = .ItemData(0)
End With
Call cboTypes_AfterUpdate
End If
End With

' Turn off hourglass
DoCmd.Hourglass False

End If

End Sub
 
D

Dan Artuso

Hi,
Is the error occuring in the function below or in adhGetOutlook() ?
Set some break points and step through the code.
 
K

Kevin

Dan,

Thanks for responding. I solved it by restarting Access.
When I restarted the application, I was able to connect.
I am still having problems though because it can't find a
list of profiles. I only have one e-mail account though
so I am planning on just inserting the username and
password. I am currently looking at where best to do that.

Thanks again for the help!

Kevin
-----Original Message-----
Hi,
Is the error occuring in the function below or in adhGetOutlook() ?
Set some break points and step through the code.

--
HTH
Dan Artuso, Access MVP


"Kevin" <[email protected]> wrote in
message news:[email protected]...
 
M

Mike Painter

Kevin said:
I am trying to setup a connection to Outlook. I need to
gain access to the contacts database and I want be able
to setup alerts etc. based on information in the contacts
database. I am looking at the Access 97 Developers
Handbook and have the code shown below from that book.
We don't need no stinkin code no more.
Time to buy a new book or read the help file.
Get External data/ Link and pick Outlook as the type
Select contacts and you are done.
 

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