|
-
Apr 15th, 2004, 03:02 PM
#1
Thread Starter
Member
[RESOLVED] ** MailItem in Outlook
I have the following code that will move all messages from the Inbox to a folder the user selects from the "Select Folder" dialog box:
Code:
Sub LAC_MoveMail()
Dim ns As NameSpace
Dim Inbox As MAPIFolder
Dim Item As Object
Dim ca As MailItem
Dim myNewFolder As MAPIFolder
Set ns = GetNamespace("MAPI")
Set Inbox = ns.GetDefaultFolder(olFolderInbox)
Set myNewFolder = ns.PickFolder
Set ca = Inbox.Items.GetFirst
While TypeName(ca) <> "Nothing"
ca.Move myNewFolder
Set ca = Inbox.Items.GetNext
Wend
Set ca = Inbox.Items.GetLast
ca.Move myNewFolder
End Sub
Problem? When there is a meeting request in the users inbox, they get a run-time error - Type Mismatch. It's occuring on the
Code:
set ca = inbox.items.getnext
because ca is a MailItem Object. My question? How do I determine what type of objects are in the Inbox?
Last edited by charlie79; Apr 16th, 2004 at 07:58 AM.
-
Apr 15th, 2004, 11:17 PM
#2
Try this. It will move only MailItems. You can add more to it to
handel other types.
VB Code:
Private Sub LAC_MoveMail_Click()
Dim ns As NameSpace
Dim Inbox As MAPIFolder
Dim Item As Object
Dim ca As MailItem
Dim myNewFolder As MAPIFolder
Dim i As Integer
MousePointer = vbHourglass
Set ns = GetNamespace("MAPI")
Set Inbox = ns.GetDefaultFolder(olFolderInbox)
ReSelect:
Set myNewFolder = ns.PickFolder
If TypeName(myNewFolder) = "Nothing" Then
MousePointer = vbNormal
GoTo No_Bugs_Exit
End If
If myNewFolder.DefaultItemType <> olMailItem Then
If MsgBox("Select Outlook MailItem type only!", vbOKCancel + vbInformation, App.ProductName) = vbOK Then
GoTo ReSelect
Else
GoTo No_Bugs_Exit
End If
End If
For i = Inbox.Items.Count To 1 Step -1
If Inbox.Items.Item(i).Class = olMail Then
Set ca = Inbox.Items.Item(i)
ca.Move myNewFolder
End If
Set ca = Nothing
Next
MousePointer = vbNormal
No_Bugs_Exit:
Set ns = Nothing
Set myNewFolder = Nothing
End Sub
Last edited by RobDog888; Apr 15th, 2004 at 11:20 PM.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|