move to Outlook Folder

G

Guest

I have an Access DB that links to a shared mailbox in Outlook (linked to the
Inbox). I have query that logs the receipt times of each email coming into
the mailbox. Please note that I the linked mailbox is not my default Inbox.
This DB is linked to shared mailbox on our server. I want to know if it is
possible to create code that will have MS Access move specific emails to
specific folder within this shared mailbox?
I have already created a form that will allow the user to view each email
separately. They will then select a folder to move the email to from a drop
down menu on this form. I want Access to then move the email to this folder
and out of the Inbox within Outlook. If anyone has any idea how to do this I
would love to hear some of your suggestions.
 
S

Sue Mosher [MVP-Outlook]

Only if you have the entire mailbox visible in your Outlook folder list, in other words, only if the mailbox added as a secondary mailbox through your Exchange account settings.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
S

Sue Mosher [MVP-Outlook]

To use the Move method, you need a MAPIFolder object for the target folder. To get a non-default folder in another mailbox, walk the folder hierarchy using the Folders collections or use a function that does that for you. See http://www.outlookcode.com/d/code/getfolder.htm
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


Hlewis said:
It is visible in my Outlook folder. What would I do next?
 
G

Guest

Sue,
I looked at this and the path appears to be "Mailbox - TLMS Cost/Inbox".
This mailbox is not in a public folder. It is at the same level as my
default mailbox. So would I use this in the sample code you provided? I'm
sorry if I'm asking silly questions but I am still very new to this. Please
be patient with me. :)
 
S

Sue Mosher [MVP-Outlook]

Yes, the basic technique of walking the folder hierarchy is the same, regardless of where in the hierarchy the folder may be located.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


Hlewis said:
Sue,
I looked at this and the path appears to be "Mailbox - TLMS Cost/Inbox".
This mailbox is not in a public folder. It is at the same level as my
default mailbox. So would I use this in the sample code you provided? I'm
sorry if I'm asking silly questions but I am still very new to this. Please
be patient with me. :)
 
S

Sue Mosher [MVP-Outlook]

You enter it before your Move statement:

Set targetFolder = GetFolder("your Outlook folder path")
theItem.Move targetFolder

where GetFolder() is the sample function I mentioned earlier.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


Hlewis said:
Okay. Where in the code to I enter the path to the folder?
 
G

Guest

I do not have a Move Statement. I looked at the code via the link you sent
and I don't think I'm following you on this. What I am trying to do is based
on a folder selected from a drop down box on an Access form, have Access move
a message from the "Inbox" to the folder selected.

Please keep in mind that I am new to all of this and really could use a
little more explaination than an experience programmer. I don't mean to be a
pain in your rear end, but you are describing things over my head. Believe
my, it does not take much to do that when it comes to writing code.

I don't know if this will help but this is what I have so far. I have
created a module with the following code:

Public Function GetFolder(strFolderPath As String) As MAPIFolder
' folder path needs to be something like
' "Public Folders\All Public Folders\Company\Sales"
Dim objApp As Outlook.Application
Dim objNS As Outlook.Namespace
Dim colFolders As Outlook.Folders
Dim objFolder As Outlook.MAPIFolder
Dim arrFolders() As String
Dim I As Long
On Error Resume Next
strFolderPath = Replace(strFolderPath, "/", "\")
arrFolders() = Split(strFolderPath, "\")
Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")
Set objFolder = objNS.Folders.Item(arrFolders(0))
If Not objFolder Is Nothing Then
For I = 1 To UBound(arrFolders)
Set colFolders = objFolder.Folders
Set objFolder = Nothing
Set objFolder = colFolders.Item(arrFolders(I))
If objFolder Is Nothing Then
Exit For
End If
Next
End If

Set GetFolder = objFolder
Set colFolders = Nothing
Set objNS = Nothing
Set objApp = Nothing
End Function

Can you briefly tell me what this code is doing. It appears that it is just
calling up the Outlook folder.

If I'm understanding your last response, I need to also have a move command
before this code? This is where I would but the following to specify the
Outlook folder to got to:
Set targetFolder = GetFolder("Mailbox - TLMS Cost")
theItem.Move targetFolder

If so, what would the code look like that would take the results of my
selection from the drop down box? What needs to happen for it to know to
move the email in the form currently visible?
 
S

Sue Mosher [MVP-Outlook]

This is what you said in your original post that you wanted to do:

To accomplish that with Outlook, you use the MailItem.Move method. What GetFolder() does is return the folder that is the target for the Move statement.
If so, what would the code look like that would take the results of my
selection from the drop down box?

Is this the dropdown box you are referring to:
They will then select a folder to move the email to from a drop down menu on this [Access] form. <<

Your earlier post suggested that this dropdown returns enough information for you to construct a string that provides the full path to the folder? If so, then you will need to use the information from that dropdown to construct the folder path string that the GetFolder() function takes as its argument. GetFolder() can then return that folder as a MAPIFolder object for use with the MailItem.Move method.

To move an item, you must have the item as an object and the folder as an object. We've already talked about the folder, so you should be set there. Now we need to talk about the item. Remember that we don't know anything about your form. What information does your Access form provide that might help retrieve the message as a MailItem object? In the Outlook world, the ideal piece of information to have is the value of the EntryID property. If you have that, then you can use the Namespace.GetItemFromID method to return the item:

Set ol = CreateObject("Outlook.Application")
Set ns = ol.GetNamespace("MAPI")
Set theItem = ns.GetItemFromID("<the EntryID value>")

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


Hlewis said:
I do not have a Move Statement. I looked at the code via the link you sent
and I don't think I'm following you on this. What I am trying to do is based
on a folder selected from a drop down box on an Access form, have Access move
a message from the "Inbox" to the folder selected.

Please keep in mind that I am new to all of this and really could use a
little more explaination than an experience programmer. I don't mean to be a
pain in your rear end, but you are describing things over my head. Believe
my, it does not take much to do that when it comes to writing code.

I don't know if this will help but this is what I have so far. I have
created a module with the following code:

Public Function GetFolder(strFolderPath As String) As MAPIFolder
' folder path needs to be something like
' "Public Folders\All Public Folders\Company\Sales"
 

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