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
R Outlook 2021 change view Using Outlook 0
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 3
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
D Send email from Outlook Alias using Mac? Using Outlook 0
G Reply a selected message and remove blank space before signature Outlook 365 version 2406 64BIT Outlook VBA and Custom Forms 2
G Reply a selected message and remove blank space before signature Outlook 365 version 2406 64BIT Outlook VBA and Custom Forms 0
kburrows "New" Outlook Desktop App Mailbox Size Using Outlook 4
N Best way to sync calendar and contacts between Outlook 365 and Outlook on iPhone Using Outlook 4
H Macro to Delete Duplicate items in Outlook calendar where title is the same and date is the same Outlook VBA and Custom Forms 0
Y The New Outlook - Q's & Thoughts Using Outlook 27
M Start Outlook 365 at unified inbox Using Outlook 2
B Requesting VBA code to make Outlook prompt for confirmation when deleting a task? Outlook VBA and Custom Forms 4
T In-line reply style in Outlook II Outlook VBA and Custom Forms 1
G Outlook Contact Item.Restrict where FullName is NULL Outlook VBA and Custom Forms 3
J Emails with .ICS calendar invitations attached don't contents when received in Outlook 365 Using Outlook 6
W Outlook 2021 Hanging on "Sending Emails" Using Outlook 3
T Outlook Desk Top 2021 Overdoing Security Using Outlook 7
O Any 3rd party tool that sync (mirror) from Outlook Contacts to Google Contacts? Using Outlook 4
D Outlook 365 Outlook Message "Cannot be sent because the message has changed" Using Outlook 0
J Hotmail drafts started on desktop disappear, but show in web version of Outlook Using Outlook 4
Z Hotmail account deleted from outlook and issue with account not exist Using Outlook 0
J 'Name on the security certificate is invalid or...' - Outlook on desktop talking to hotmail.com account Using Outlook.com accounts in Outlook 5
J Outlook, Word, Access crash unless run in Admin mode - time dependent it seems Using Outlook 10
T Why do Outlook Desktop 2021 tasks from my wife's email show up in my task pane? Using Outlook 2
B Delete Read Receipts in Your Outlook Outlook VBA and Custom Forms 0
M Outlook changes the "Modified" field when moving/copying a Contact. Using Outlook 0
macdotcom Outlook 365 Outlook folder export to PST archival tool - close, but need a nudge Outlook VBA and Custom Forms 2
M Outlook 2016 still feature updating Using Outlook 0
e_a_g_l_e_p_i Question about Outlook 2021 and Gmail Using Outlook 8
J Outlook VBA to send from Non-default Account & Data Files Outlook VBA and Custom Forms 4

Similar threads

Back
Top