Gardhi,
Let’s start by looking at how you can write code in the search form that can set a value in some other form.
In the Search form, you want to store a result into something within the calling form. That “something” should be named the same in each form that can call the Search form; it can be a control (in which case you will set the value of the control), or it can be a variable (in which case it must be public), or it can be a procedure.
Regardless of which type of target you use, your code must identify the form first. To do that, you use the application’s Forms collection, and you specify the form (as a member of the collection) by name. For example, if the Search form is called from a form named fPurchase, you would use a statement like:
Forms(“fPurchase”).txtSearchResult = vSearchResult
to transfer a result from the variable vSearchResult to the text box txtSearchResult
In a language like Visual Basic for Applications (VBA), you can use a string variable anywhere that you can use a string literal. In other words, if you have set a variable formName to the name of the calling form, you can use the statement:
Forms(formName).txtSearchResult = vSearchResult
to set the text box to the result on the form whose name is in the formName variable.
The next question is, “How can I pass the name of the calling form to the search form?” I strongly recommend that you use the OpenArgs argument.
When you use the DoCmd.OpenForm method to open a form (in this case, the Search form), the last argument is the OpenArgs parameter. You can pass anything you want to the called form as a string. In the called form, you can use the form’s OpenArgs property to retrieve the passed value.
For example, you could have a statement in the code on the Search form like:
formName = Me.OpenArgs
and then use formName to refer to the calling form. Or, if your only use of the OpenArgs property is to pass the calling form’s name, you could even use the statement:
Forms(Me.OpenArgs).txtSearchResult = vSearchResult
Michael S. Meyers-Jouan