Create search button for specific entry

What I require is a Macro witch preduces a field entry to be searched in calendar

information:
i enter data into calendar days in relation 2 items manufactured and packed ina standard format e.g

Build; 108L 21157 --B387990 or Mfg; 250Kg 21157 --B387897

the search is for the B387990 Bin number. So clicking the macro button will bring up window to enter in bin.

I have created some macro's in the past with VBscript but I am not very confidetn with the code so any help is greatly appreciated
LVL 1
mrwildeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David LeeCommented:
mrwilde,

What field are you storing the bin number in?
0
mrwildeAuthor Commented:
I have been entering it into the subject field
0
David LeeCommented:
mrwilde,

Here's my proposed solution.  The code below conducts a search and returns the results in the form of a Search Folder.  This will only work if you have Outlook 2003.  Conducting the search is easy, the more difficult part of this is displaying the search results.  Unfortunately, Microsoft doesn't seem to have given us a simple way of displaying search results.  I guess the theory was that if you searched via code, then you'd just want to act on the results, not display them.  The alternative is to create your own search results dialog-box, something that is clearly doable, but that would require more time and effort than is reasonable for an EE question.  The only alternative I could think of is to display the results in a search folder.  That's not a bad solution, but there is one problem.  There is apparently no way of getting rid of the search folder from code after we're done with it.  So it has to be deleted manually before running the search a second time.  Follow these instructions to set the code up and use it.

1.  Start Outlook
2.  Click Tools->Macro->Visual Basic Editor
3.  If not already expanded, expand Microsoft Office Outlook Objects and click on ThisOutlookSession
4.  Copy the code in Code Block A below and paste it into the right-hand pane of the VB editor window
5.  If not already expnaded, expand Modules and click on Module1
6.  Copy the code in Code Block B below and paste it into the right-hand pane of the VB editor window
7.  Click the diskette icon on the toolbar to save changes
8.  Close the VB Editor
9.  Click Tools->Macro->Security
10.  Set the Security Level to Medium
11.  Run the macro by clicking Tools->Macro->Macros and selecting BinSearch
12.  When the macro runs a dialog-box will pop up asking what you want to search for.  Enter a value or leave the field blank to cancel the search.  Use % as a wildcard.  For example, entering "B387990" will search for any item whose subject is exactly "B387990" whereas entering "%B387990" will find any item whose subject contains "B387990".
13.  The results of the search will appear in a new window in a search folder called "Bin Number".
14.  When you are done with the search, close the window and delete the Bin Number search folder.

If this works out and you're happy with the approach, then I'll also post the code for hooking this up to a toolbar button.


'<Code Block A>
Private Sub Application_AdvancedSearchComplete(ByVal SearchObject As Search)
    blnSearchComp = True
End Sub
'</Code Block A>

'<Code Block B>
Public blnSearchComp As Boolean

Public Sub BinSearch()
    Dim olkSearch As Outlook.Search, _
        olkSearchFolder As Outlook.MAPIFolder, _
        strCondition As String, _
        strFolder As String, _
        strValue As String
    strValue = InputBox("What value shall I search for?" & vbCrLf & "(Use % for a wildcard)", "Bin Search")
    If strValue <> "" Then
        blnSearchComp = False
        strCondition = "urn:schemas:mailheader:subject LIKE '" & strValue & "'"
        strFolder = "Calendar"
        Set olkSearch = Application.AdvancedSearch(strFolder, strCondition)
        While blnSearchComp = False
            DoEvents
        Wend
        Set olkSearchFolder = olkSearch.Save("Bin Number")
        olkSearchFolder.Display
    End If
    Set olkSearch = Nothing
    Set olkSearchFolder = Nothing
End Sub
'</Code Block B>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

mrwildeAuthor Commented:
Thanks so much, it looks like you put some work into it

I have entered the code you given me into the editor. When running the macro I get the dialog box but no results window. Some points of interest

there are several other macros in the module listing where I placed the B block of code. Does this code need presedence?

Every entry is in the subject line of the calendar like this
Mfg; 250Kg 21157 --B387897
Can we set up the search to always allow for the wildcard?


what should i look for in the macro that is stopping?

0
David LeeCommented:
You're welcome.  No, the order the macros are in doesn't make any difference.  The procedure names (i.e. Sub X, or Function Y) just need to be unique.  They must be or you'd have gotten an "ambiguous name" error.  Yes, we can change the macro to automatically include the wildcard.  Change this line

    strValue = InputBox("What value shall I search for?" & vbCrLf & "(Use % for a wildcard)", "Bin Search")

to

    strValue = InputBox("What value shall I search for?", "Bin Search")

And this line

    strCondition = "urn:schemas:mailheader:subject LIKE '" & strValue & "'"

to

    strCondition = "urn:schemas:mailheader:subject LIKE '%" & strValue & "'"


Are the items you're searching for in your default calendar?
0
mrwildeAuthor Commented:
No they are not
0
David LeeCommented:
Then that's why we aren't finding them.  Where are they?
0
mrwildeAuthor Commented:
Calendar in public folder
0
mrwildeAuthor Commented:
IT Managment in Public Folders
0
David LeeCommented:
Change this line

    strFolder = "Calendar"

to

    strFolder = "'\\Public Folders\All Public Folders\IT Management'"
0
mrwildeAuthor Commented:
I have recieved an error
---------------------------
Microsoft Visual Basic
---------------------------
Compile error:

End If without block If
---------------------------
OK   Help  
---------------------------
what do ya reckon?
0
mrwildeAuthor Commented:
it's ok I found the line I accidently deleted

but it returned an error after entering the search criteria

runtime error '-2147024809 (80070057)':

Could not preform the operation. One or more parameter values are not valid

then when I select debug it highlights this line
Set olkSearch = Application.AdvancedSearch(strFolder, strCondition)
0
David LeeCommented:
There's only one IF and one corresponding END IF in the code.  Are they still there?  If so, then look to see that there are a matching number of quotes (both single and double) and parenthesis on the lines between the IF and END IF.  Pay particular attention to the lines we just changed.
0
David LeeCommented:
Look at the strFolder line we just changed.  Is the public folder path correct?  Is that path surrounded by "' and '" (double quote single quote and single quote double quote)?
0
mrwildeAuthor Commented:
Closer inspection revealed I cant spell
IT Managment is the folder name

So changed that and recieved this error

The operation Failed

entering the Debug highlighted this
Set olkSearchFolder = olkSearch.Save("Bin Number")
0
David LeeCommented:
Take a look at Search Folders and see if a folder with that name already exists.
0
mrwildeAuthor Commented:
Sorry for the delay in my reply, system errors

I still have the error
and the highlight

Set olkSearchFolder = olkSearch.Save("Bin Number")

No there is no other folder in the search folders
0
David LeeCommented:
As a test, try changing the folder name (i.e. change "Bin Number" to something else) and see what happens.  I've run the script here repeatedly and the only time I get and error on that line is when a fodler with the same name already exists.  If the save works with the different folder name, then there must be a folder called "Bin Number" there somewhere.  If it fails, then something else is wrong.
0
David LeeCommented:
I believe I deserve credit for answering this question.  
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Outlook

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.