Automating Outlook session from Access

J

Justin

Hello all. I have a question about automation and public
email boxes. I have created a database that will import
items from an email box into a table. It allows the user
to pick from a folder in their outlook. It stores the
folder's entryid and storeid in a table to use when
importing. But, I've encountered a strange problem when
the user selects a public folder and then tries to run
any of the routines. If the user had started Outlook
themselves it will recognize the folder just fine. If
Outlook was started programatically, it does not find the
folder. Below is the code I use to initialize the otlApp
variable:

Private Sub otlIni()
On Error GoTo constErr

Set otlApp = GetObject(, "Outlook.Application")

constErr:
Select Case Err.Number
Case 0
Case 429 ' Outlook not open
Set otlApp = CreateObject
("Outlook.Application")

Case Else
MsgBox "Error: " & Err.Number & ". " &
Err.Description
End Select

End Sub

Here is the function I use to get the folder that the
user selected:

Function otlGetFolderFromID(strEntryID As String,
strStoreID As String) As Outlook.MAPIFolder
On Error Resume Next

If otlApp Is Nothing Then
otlIni
End If


Set otlGetFolderFromID =
otlApp.Session.GetFolderFromID(strEntryID)

End Function

I have a simple test routine that basically just displays
all of the emails in the folder. But, if it is a public
folder and the otlApp was initialized using the
CreateObject function, then the otlGetFolderFromID
function fails. Is there some other step that I am
missing to initialize the session so that it recognizes
the public folders id's? Thanks in advance for your help!
 
G

Guest

Yep, just realized that after I posted this. But now I
am having a diff problem. For some reason now when I try
to set a variable = otlGetFolderFromID, it sets it =
nothing. From debugging I find the function is finding
the folder ok and has a value before exiting, it's just
not setting the variable equal to it.
 
S

Sue Mosher [MVP-Outlook]

Try specifying a value for the StoreID argument in your
Namespace.GetFolderFromID statement.
 
G

Guest

Nevermind, seems to be working fine now. Not sure what
happened. Think it was a problem with the otlApp losing
its value. Anyways, thanks for your help!
 

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