|
Question : Using msoControlEdit to enter search parameter?
|
|
Hi,
I am using CommandBar coding to create shortcut menus for my forms. I'm no expert but I've done pretty well so far.
I would like to be able to add a Text Control (msoControlEdit) to my Shortcut Menu where I can enter a name (e.g., "Michael") that i want to search for; after I enter the text and click the enter key, I want Access to go to a field on my form and look for the text "Michael" using docmd.findrecord and referencing the text I've entered in my shortcut text box.
I guess all I need to know is how do I reference the input text in my function I'll use to find the text? I will then use that function as my .OnAction.
I hope that makes sense. Easy question, just don't know how to reference the parameter I've entered on the menu.
Bill
|
|
Answer : Using msoControlEdit to enter search parameter?
|
|
You can set the OnAction of your commadbar control to be a custom Function you've defined in a Standard Module, and use that function to refer back to the edit box. For example, in my db I've created a MenuBar named "ScottsBar", and on that is a Combo (aka a "CommandBarPopup") named "MyMenu". MyMenu has an Edit control named "Textbox1". I've set the OnAction property of Textbox1 to this:
=fncSearch()
Note that you MUST use this syntax, including the equals sign and parentheses. You could, of course, alter the code below to do something more than popup a messagebox; in your case, I'm assuming you know how to initaiate your search features and such.
'/ Add this code to a Standard Module; you'll of course need to change the names of the MenuBar and controls to match your own Public Function fncSearch()
Dim pop As Office.CommandBarPopup Dim ctlEdit As Office.CommandBarControl
Set pop = Application.CommandBars("ScottsBar").Controls("MyMenu") Set ctlEdit = pop.Controls("Textbox1")
MsgBox pop.Controls("Textbox1").Text
Set cltedit = Nothing Set pop = Nothing
End Function
|
|
|
|