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
L Android Outlook Doesn't Update PC Notification Changes Using Outlook 0
A How to open Excel file saved in Outlook folder? Outlook VBA and Custom Forms 4
D.Moore Outlook desktop client suggested searches question Using Outlook 10
Y Outlook 2016 (64-bit) Copy Local Cal. Events to Another Cal. with Modified Reminder time Using Outlook 2
T Outlook 2019 While connecting an IMAP account in "classic" Outlook 2024 I caused a massive duplication of emails on the server (death loop) Using Outlook 5
D Cannot logon to Outlook.com, or outlook on Mac, outlook not updating on ipad, iphone Using Outlook 1
J unable to get my new install of Outlook to display mailboxes in the single-line format. Using Outlook 1
D Legacy Microsoft Outlook for Mac Support will end in Oct 2025 Using Outlook 5
C Nasty Bug Lurking In Outlook For Years. The Trigger. Any Fix Or Workaround? Using Outlook 11
R Auto clicking Hyperlink in outlook Outlook VBA and Custom Forms 7
ughlook Open multiple contacts in NEW Outlook? Using Outlook 3
G Outlook translation feature is off Using Outlook 2
J Outlook 2010 does not let me put any account Using Outlook.com accounts in Outlook 3
P 3 of 5 PST files don't install from d:\outlook but only from D:\ Using Outlook 7
HarvMan January Windows 10 preview update force installs new Outlook Using Outlook 1
L Outlook 2010 - new installation on Windows 11 - aplzod32.dll is not a valid Add-in Using Outlook 12
J Outlook troubleshooting/logging - option grayed out Using Outlook 2
B Arrows missing from Outlook emails vertical scrollbar Using Outlook 0
G Outlook 2021 (New) doesn't respect default browser Using Outlook 9
B Outlook or iPhone turning tabs into spaces in Outlook Notes Using Outlook 1
P newly installed Office 365 includes OLD Outlook Using Outlook 6
R Outlook ribbon menu default? Using Outlook 7
H Spam email in Gmail not visible in Outlook Using Outlook 3
J How to transfer Win 10 Outlook to new Windows 11 pc? Using Outlook 16
J Renegade spam URL line displayed in old local Outlook 365 email title Using Outlook 3
G Reduce whitespace in Outlook desktop Contact Cards display Using Outlook 3
C Outlook classic via 365 Using Outlook 2
Dr. Demento Analogous Outlook code to read info into an array (or collection or whatever) Outlook VBA and Custom Forms 7
S Repair Outlook Using Outlook 8
V Outlook Form ListBox is not editable Outlook VBA and Custom Forms 2
F Outlook's contacts Using Outlook 1
D Outlook 2003 stopped dead Using Outlook 2
G Cannot receive emails from gmail account in Outlook 365 Using Outlook 1
E "Cannot display the folder. MS Outlook cannot access the specified file location" Using Outlook 8
P Outlook 2016 Working Offline Using Outlook 2
Rupert Dragwater Cannot reestablish gmail (email address) account in Outlook 365 Using Outlook 11
O Outlook 365 synchronisieren Exchange Server Administration 1
kburrows Outlook Classic - JPG files are corrupted when opened or saved Using Outlook 3

Similar threads

Back
Top