A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook - Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Outlook Advanced Search Problems...returns with an Error: Argument



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old October 1st 09, 12:33 AM posted to microsoft.public.outlook.program_forms
amatuercoder151
external usenet poster
 
Posts: 1
Default Outlook Advanced Search Problems...returns with an Error: Argument

Hi All,
I am facing a problem with using the advanced search function provided in
the outlook object model.
What i am trying to achieve is simple. I just want to open a pst, and able
to run a search on all the items( calender, mail, appointment...everything),
and then just get the all items count...thats all..
The code i have written is as follows:

Dim app As New Application
Dim pstinfo As [NameSpace]
pstinfo = app.GetNamespace("MAPI")
Dim objfolder As MAPIFolder = Nothing
app.Session.Logon("outlook", "", False, True)
Dim allfolders As Microsoft.Office.Interop.Outlook.Folders =
pstinfo.Folders
Dim i As Integer = 0
Dim ii As Integer = 0
Dim foldernames(10) As String
For Each folder In allfolders
Dim objtempfolder As MAPIFolder = folder
foldernames(i) = objtempfolder.Name
i = i + 1

Next
pstinfo.Session.AddStore(PST NAME HERE)

Dim matchfound As Integer = 0
For Each folder In pstinfo.Folders
matchfound = 0
Dim objtempfolder1 As MAPIFolder = folder
For i = 0 To 10
If objtempfolder1.Name = foldernames(i) Then
matchfound = 1
Exit For

End If
Next
If matchfound = 0 Then
objfolder = objtempfolder1
End If

Next

Dim scope As String = Nothing
scope = "'" & objfolder.folderpath & "'"

Dim search As Search = app.Session.Application.AdvancedSearch(scope,
, True, "")
pstinfo.Session.RemoveStore(objfolder)
app = Nothing
pstinfo = Nothing
objfolder = Nothing
search = Nothing
System.GC.Collect()


Private Sub app_AdvancedSearchComplete(ByVal SearchObject As
Microsoft.Office.Interop.Outlook.Search) Handles app.AdvancedSearchComplete
Dim results As Results
results = SearchObject.Results()
MsgBox("The Total Number of found in the PST A " & results.Count)
End Sub

This code works totally fine with almost all the PST's, until i encountered
a PST which had a mailbox named " Archived Folders". Thereby the
objfolder.folderpath variable comes out to be "\\ Archived Folders", and the
advanced search line throws an error saying Error: Argument Exception was
Unhandled:Could not complete the operation. One or more parameter values are
not valid.
For all others its working. Also one thing to mention is that "\\ Archived
Folders" has a starting space character, which i feel might be the problem.
Please if somebody could help me out, as i have tried all things, but
nothing works

Ads
  #2  
Old October 1st 09, 02:13 PM posted to microsoft.public.outlook.program_forms
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Outlook Advanced Search Problems...returns with an Error: Argument

See if replacing any spaces with "%20" works.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"amatuercoder151" wrote in
message ...
Hi All,
I am facing a problem with using the advanced search function provided in
the outlook object model.
What i am trying to achieve is simple. I just want to open a pst, and able
to run a search on all the items( calender, mail,
appointment...everything),
and then just get the all items count...thats all..
The code i have written is as follows:

Dim app As New Application
Dim pstinfo As [NameSpace]
pstinfo = app.GetNamespace("MAPI")
Dim objfolder As MAPIFolder = Nothing
app.Session.Logon("outlook", "", False, True)
Dim allfolders As Microsoft.Office.Interop.Outlook.Folders =
pstinfo.Folders
Dim i As Integer = 0
Dim ii As Integer = 0
Dim foldernames(10) As String
For Each folder In allfolders
Dim objtempfolder As MAPIFolder = folder
foldernames(i) = objtempfolder.Name
i = i + 1

Next
pstinfo.Session.AddStore(PST NAME HERE)

Dim matchfound As Integer = 0
For Each folder In pstinfo.Folders
matchfound = 0
Dim objtempfolder1 As MAPIFolder = folder
For i = 0 To 10
If objtempfolder1.Name = foldernames(i) Then
matchfound = 1
Exit For

End If
Next
If matchfound = 0 Then
objfolder = objtempfolder1
End If

Next

Dim scope As String = Nothing
scope = "'" & objfolder.folderpath & "'"

Dim search As Search =
app.Session.Application.AdvancedSearch(scope,
, True, "")
pstinfo.Session.RemoveStore(objfolder)
app = Nothing
pstinfo = Nothing
objfolder = Nothing
search = Nothing
System.GC.Collect()


Private Sub app_AdvancedSearchComplete(ByVal SearchObject As
Microsoft.Office.Interop.Outlook.Search) Handles
app.AdvancedSearchComplete
Dim results As Results
results = SearchObject.Results()
MsgBox("The Total Number of found in the PST A " &
results.Count)
End Sub

This code works totally fine with almost all the PST's, until i
encountered
a PST which had a mailbox named " Archived Folders". Thereby the
objfolder.folderpath variable comes out to be "\\ Archived Folders", and
the
advanced search line throws an error saying Error: Argument Exception was
Unhandled:Could not complete the operation. One or more parameter values
are
not valid.
For all others its working. Also one thing to mention is that "\\ Archived
Folders" has a starting space character, which i feel might be the
problem.
Please if somebody could help me out, as i have tried all things, but
nothing works


 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using the search returns no results outlook 2007 macsaintly Outlook - Using Contacts 18 March 15th 10 09:46 AM
Instant Search, Advanced Find, Search Folders, and Windows Desktop [email protected] Outlook - General Queries 2 October 31st 08 06:37 PM
Outlook search and advanced search not working (tried rebuilding the index) Bradley Burton Outlook - General Queries 2 July 22nd 08 07:31 PM
Outlook 2007 returns error message 0x80042108 The Magician Outlook - General Queries 1 July 9th 08 07:59 PM
Outlook 2007 Search always returns no matches Tom Outlook - General Queries 3 January 24th 07 11:01 PM


All times are GMT +1. The time now is 02:46 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2024 Outlook Banter.
The comments are property of their posters.