Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Create search button for specific entry

Posted on 2006-03-23
20
Medium Priority
?
296 Views
Last Modified: 2012-06-22
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
0
Comment
Question by:mrwilde
  • 10
  • 9
19 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 16295399
mrwilde,

What field are you storing the bin number in?
0
 
LVL 1

Author Comment

by:mrwilde
ID: 16305421
I have been entering it into the subject field
0
 
LVL 76

Accepted Solution

by:
David Lee earned 1500 total points
ID: 16309426
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
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 
LVL 1

Author Comment

by:mrwilde
ID: 16315921
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
 
LVL 76

Expert Comment

by:David Lee
ID: 16316054
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
 
LVL 1

Author Comment

by:mrwilde
ID: 16316116
No they are not
0
 
LVL 76

Expert Comment

by:David Lee
ID: 16316211
Then that's why we aren't finding them.  Where are they?
0
 
LVL 1

Author Comment

by:mrwilde
ID: 16316254
Calendar in public folder
0
 
LVL 1

Author Comment

by:mrwilde
ID: 16316260
IT Managment in Public Folders
0
 
LVL 76

Expert Comment

by:David Lee
ID: 16316409
Change this line

    strFolder = "Calendar"

to

    strFolder = "'\\Public Folders\All Public Folders\IT Management'"
0
 
LVL 1

Author Comment

by:mrwilde
ID: 16316683
I have recieved an error
---------------------------
Microsoft Visual Basic
---------------------------
Compile error:

End If without block If
---------------------------
OK   Help  
---------------------------
what do ya reckon?
0
 
LVL 1

Author Comment

by:mrwilde
ID: 16316795
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
 
LVL 76

Expert Comment

by:David Lee
ID: 16316859
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
 
LVL 76

Expert Comment

by:David Lee
ID: 16316888
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
 
LVL 1

Author Comment

by:mrwilde
ID: 16317000
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
 
LVL 76

Expert Comment

by:David Lee
ID: 16317150
Take a look at Search Folders and see if a folder with that name already exists.
0
 
LVL 1

Author Comment

by:mrwilde
ID: 16396819
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
 
LVL 76

Expert Comment

by:David Lee
ID: 16396861
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
 
LVL 76

Expert Comment

by:David Lee
ID: 16601003
I believe I deserve credit for answering this question.  
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you troubleshoot Outlook for clients, you may want to know a bit more about the OST file before doing your next job. IMAP can cause a lot of drama if removed in the accounts without backing up.
Today as you open your Outlook, you witness an error message: “Outlook is using an old copy of your Outlook Data File…”. Probably, Outlook is accessing an old OST file.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question