I am essentially looking for a bit of code which will allow me to refer to an unspecified MAPI folder. Just to put that into context, My code creates a new folder if there is a new sender, the new folder is automatically created by using the domain name of the senders email address. I then want to move the relevant email into that folder (which is why it is unspecified) does anybody know how I would go about this?
VBA Outlook MAPI Folders Error: 'Cannot Move Emails' - refer to unspecified folder?
Collapse
X
-
Code:Set rstClient = db.OpenRecordset("Select foldername from tbl001_clientdetails where hostname = '" & strClientHost & "'") If "'" & strFolderName & "'" <> rstClient!FolderName Then 'Set new folder for client and move emails into it Set outOutlook = CreateObject("Outlook.Application") Set outNamespace = outOutlook.GetNamespace("MAPI") Set outItem = outNamespace.GetDefaultFolder(olFolderInbox) Set outFoldersClient = outFoldersClient.Folders("'" & strFolderName & "'") outItem.Folders.Add ("'" & strFolderName & "'") Set outOutlook = Nothing Set outNamespace = Nothing Set outItem = Nothing Else MailObject.Move outFoldersClient End If
Comment
-
-
On Error GoTo Err_funErrorChe cking
Dim outNamespace 'As Outlook.NameSpa ce
Dim outOutlook 'As Outlook.Applica tion
Dim MailObject 'As Outlook.MailIte m
Dim outItem 'As Outlook.MailIte m
Dim outFolder As MAPIFolder
Dim outFoldersUnaut horised As MAPIFolder
Dim outFoldersActio ned As MAPIFolder
Dim outFoldersNewSe nder As MAPIFolder
Dim outFoldersClien t As MAPIFolder
Dim InboxItems As Outlook.Items
Dim intCount As Integer
Dim intMove As Integer
Dim strAnswer As String
Dim intAnswer As Integer
Dim strField As String
Dim rstFolders As DAO.Recordset
Dim rstAdmin As DAO.Recordset
Dim intID As Integer
Dim strRequestID As String
Dim intContactID As Integer
Dim rstData As DAO.Recordset
Dim rstUserData As DAO.Recordset
Dim rstPathData As DAO.Recordset
Dim db As Database
Dim strEmailAddress As String
Dim rstContactCheck As DAO.Recordset
Dim rstSupportReque st As DAO.Recordset
Dim intunauthorised As Integer
Dim intnewsender As Integer
Dim intuncount As Integer
Dim intnewcount As Integer
Dim strClientEmail As String
Dim strProBaseEmail As String
Dim rstClient As DAO.Recordset
Dim rstClientEmail As DAO.Recordset
Dim strHostName As String
Dim strClientHost As String
Dim strFolderName As String
Dim rstAssignee As DAO.Recordset
Dim intposition As Integer
Dim strContactName As String
Dim rstAuthorised As String
Dim strsubjectyes As String
Dim strsubjectno As String
CheersComment
-
Wow, be careful what you ask for. Rebecca, I created some Demo Code for you that appears to work quite well, but has not been extensively tested. I'll leave that part up to you. Good Luck, and let us know how you make out.
Code:'The following Code will create a New Folder under Inbox, then move all 'Mail to this new Destination Directory, from Inbox Dim outOutlook As New Outlook.Application Dim outNamespace As Outlook.NameSpace Dim myInbox As Outlook.MAPIFolder Dim myDestFolder As Outlook.MAPIFolder Dim outItems As Outlook.Items Dim outItem As Object Dim strFolderName As String strFolderName = "YaDa-YaDa" 'Destination Folder Set outNamespace = outOutlook.GetNamespace("MAPI") Set myInbox = outNamespace.GetDefaultFolder(olFolderInbox) 'Set myInbox = outNamespace.GetDefaultFolder(olFolderDrafts) Drafts Folder Set outItems = myInbox.Items myInbox.Folders.Add strFolderName 'Add Destination Folder under Inbox Set myDestFolder = myInbox.Folders(strFolderName) DoCmd.Hourglass True 'Move each Mail Item to the Destination Folder For Each outItem In outItems outItem.Move myDestFolder Next '********************************************************************* 'To Move Mail for a specific Sender * 'Set outItem = outItems.Find("[SenderName] = 'Herman Munster'") * 'While TypeName(myItem) <> "Nothing" * 'myItem.Move myDestFolder * 'Set myItem = myItems.FindNext * 'Wend * '********************************************************************* DoCmd.Hourglass False MsgBox "Mail has been moved from " & myInbox.Name & " to " & strFolderName & "!", _ vbInformation, "Mail Move" Set outOutlook = Nothing Set outNamespace = Nothing Set outItem = Nothing
Comment
-
Wow, it actually worked! Thanks so much... no body else could understand what I wanted to do!
Thank you!!Comment
Comment