Searching Outlook Public Folders

Joined
Feb 9, 2010
Messages
2
Reaction score
0
Searching Outlook Public Folders [RESOLVED]

I have the following coding:

Code:
 Dim dteBegin AsDate = Now 
dteBegin = DateAdd(DateInterval.Month, -1, dteBegin) 
strRestrictFilter = "[ReceivedTime] > '" & FormatDateTime(dteBegin, DateFormat.ShortDate) & "'"
objFoundItems = objLargeFolder.Items.Restrict(strRestrictFilter)
 
Dim intFN AsInteger
For intFN = 1 To objFoundItems.Count 
If objFoundItems(intFN).Class = Outlook.OlObjectClass.olMail Then 
objMailItem = CType(objFoundItems(intFN), Outlook.MailItem) 
Debug.Print(objMailItem.ReceivedTime & " - " & objMailItem.Subject) 
Else 
Debug.Print(objFoundItems(intFN).Class.ToString) 
EndIf
 
Next


All objects have been set appropriately & the code works fine for a while, then out of nowhere it errors at the CType line. This is the error:

"When casting from a number, the value must be a number less than infinity."
That doesn't make much sense to me. This is the exception detail:
System.InvalidCastException was unhandled
Message="Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Outlook.MailItem'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00063034-0000-0000-C000-000000000046}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))."
Source="EMailCounter"
StackTrace:
at EMailCounter.frmMain.cmdCreate_Click(Object sender, EventArgs e) in C:\Documents and Settings\sneckelmann\My Documents\Visual Studio 2008\Projects\EMailCounter\EMailCounter\frmMain.vb:line 34
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at EMailCounter.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:

Any idea what I'm doing wrong? Thanks for your help.
 
Last edited:

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