search boxes

jprma

Registered User.
Local time
Today, 20:47
Joined
Dec 19, 2000
Messages
18
Hi friends, I am back for help. In my database (MS ACCESS 97) I have a form named frmQueries on to which I have added a TAB CONTROL which has 5 pages. The first page is named ALPHA. On this page I have added various text boxes into which the user can type the criteria to search. To run the query, I have created for each text box a command button which makes the query run.
Obviously the query itself has the following criteria:
Like "*" & [forms]![frmQueries]![txtsearch1] & "*"
frmQueries is the form and txtsearch1 is the name of the text box into which type the information.
Do you think is possible to use just one command button for all the text boxes? How could I associate all the events to one, unique button?
Thanks
 
You can use the PreviousControl method of the Screen object to return a reference to the last control to have the focus on your form. Once you store this reference in an object variable, you have access to the properties of the original control (including the Tag property)...
Private Sub Command4_Click()
Dim ctl As Control

Set ctl = Screen.PreviousControl

' Previous Control name = ctl.name
' Previous Control Tag = ctl.Tag

End Sub

...Using the propery sheet of the Control put a value in the Tag property that evaluates to the full reference name of the control...

Text1.Tag = [Forms]![Form1]![Text1]

... Then you can have a generic call to you query using the Tag as a condition...

LIKE "*" & ctl.Tag & "*"


...HTH
Chris
 

Users who are viewing this thread

Back
Top Bottom