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

  • Thread starter Thread starter amatuercoder151
  • Start date Start date
Status
Not open for further replies.
A

amatuercoder151

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 Are: " & 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
 
See if replacing any spaces with "%20" works.

"amatuercoder151" <amatuercoder151> wrote in

message news:3A5C0A37-80A8-40F8-B084-C7103B7029D1@microsoft.com...
> 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 Are: " &
> 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
>
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
farrissf Outlook 2016 Optimizing Email Searches in Outlook 2016: Seeking Insights on Quick Search vs Advanced Search Features Using Outlook 0
C Advanced search terms for "Outlook Data File" Using Outlook 1
mll persistently customise columns in outlook advanced search Using Outlook 3
R Outlook for Mac - Advanced Search and Tracking Sent Emails Using Outlook 0
B Advanced Search in MS Outlook by VBA and SQL Outlook VBA and Custom Forms 2
T Outlook 2007 Indexing Options and Advanced Search options disabled Using Outlook 5
S Related messages show in main Outlook window vice new Advanced Find windows Using Outlook 1
P Outlook Advanced Find Using Outlook 0
N Outlook 2010 crippled Advanced Find, now what? Using Outlook 3
H Outlook 2010 Advanced Find - Menu items missing Using Outlook 1
D Outlook 2010 - Advanced Find - No Status Bar = No Item Count Using Outlook 2
J Advanced outlook trick: help needed! Outlook VBA and Custom Forms 3
Dr. Demento Analogous Outlook code to read info into an array (or collection or whatever) Outlook VBA and Custom Forms 1
S Repair Outlook Using Outlook 5
V Outlook Form ListBox is not editable Outlook VBA and Custom Forms 0
F Outlook's contacts Using Outlook 0
D Outlook 2003 stopped dead Using Outlook 2
G Cannot receive emails from gmail account in Outlook 365 Using Outlook 0
E "Cannot display the folder. MS Outlook cannot access the specified file location" Using Outlook 4
P Outlook 2016 Working Offline Using Outlook 2
Rupert Dragwater Cannot reestablish gmail (email address) account in Outlook 365 Using Outlook 12
O Outlook 365 synchronisieren Exchange Server Administration 1
kburrows Outlook Classic - JPG files are corrupted when opened or saved Using Outlook 3
F Sync Outlook Calendar Using Outlook 0
G Change default font size in sticky notes - Outlook Desktop 2021 Using Outlook 2
C VBA in "New Outlook?" Using Outlook 0
D New Outlook with Business Basic Plans Using Outlook 0
D Outlook 2021 not working with Outlook 2003 installed Using Outlook 5
D Outlook 2003 stopped working - get they dialog box asking for username & Password Using Outlook 2
T Outlook 2021 hangs in close on taskbar occasionally Using Outlook 1
M Duplicate removal feature in Outlook 2021 is faulty Using Outlook 2
D.Moore Outlook COM addins source folder Using Outlook 13
P Removing Outlook 365 Account from Send/Receive Using Outlook 3
kburrows Outlook Automatically Merging Contacts Using Outlook 2
A Outlook 2016 Outlook 2016 vs. New Outlook Using Outlook 4
D Outlook Desktop App Email Software Using Outlook 0
efire9207 VBA Outlook Contacts Outlook VBA and Custom Forms 6
M Outlook not logging in to server Using Outlook 0
J Outlook macro to run before email is being send Outlook VBA and Custom Forms 3
R Outlook 2021 change view Using Outlook 2
K Outlook font corrupted in some point sizes, resets on close/open Using Outlook 2
J Is the Windows Outlook Tasks module really going to be gone? Using Outlook 6
F Outlook 2010 and Hotmail Using Outlook 1
A Outlook 2021 needs 'enter' for people search Using Outlook 2
HarvMan Outlook 365 Inbox Font Using Outlook 8
Retired Geek Outlook on MAC delete duplicate Sent emails Using Outlook 0
S New Outlook - IMAP ISSUES and support for addins? Using Outlook 1
C outlook.com fonts Using Outlook 2
mickymakz Common challenges organizations face when integrating SharePoint and Outlook? Exchange Server Administration 0
R Outlook with several IMAP accounts generating folders with 1111 suffix Using Outlook 0

Similar threads

Back
Top