Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Interactive Query 2

Status
Not open for further replies.

agape234

Programmer
Oct 10, 2001
128
US
I have a table with about 20 columns and 20,000 rows.
I need an "interactive" query that will allow the user to open a query to pull up a record based on the data in column X.
IE.......
Query.......entire db for value=123456 in column x.
Thanks
 
if just for column x, put in the query criteria for column x: [enter value] (or whatever you want). When it run it will popup an entry box.
 
Hi,
Create a select query using this table as it's data source. Pull all fields into the query. In Column X's criteria add
"[Enter a Column X]". (e.g. If Column X is a last name field you might use something like [Enter a last name].)
You can activate this query using a button in a form. Simplest way to do that is to create a Command Button using the control wizard (choose Miscellaneous/Run Query, follow instructions). Or you can use a macro to activate your query. Or you can employ the DoCmd.OpenQuery "qry_name" syntax in your VB code behind the scenes.
When your user causes the query to run by clicking the button, running the macro or the VB code, they will be prompted with "Enter a last name", and the query will return the appropriate result set. You may place these prompts on more than one field in the query.
Hope this helps.
Q
 
Are you asking how to do this for a set field of the 20, or are you asking how to do this for ANY field of the 20?

If for a set field, use the method suggested by FirstandGoal4 and Qu1ncy.

If you want the users to be able to query any field in the table, here is one approach you could try.

1. Create an unbound form with two combo boxes, an OK button and a Cancel button on it

2. For the first combo box, set its Row Source to a value list of the name of every field in your table.

3. For the second combo box, use a SQL string to set the Row Source to all the values of the field chosen in the first combo box. This string would be run from the On Change event of the first combo box.

4. In the On Click code of the OK button, run a SQL string to run the query, setting a WHERE clause along the lines of "WHERE [SelectedField] = [Selected Value]".

This should then work for any value in any field within the table. If there are too many values to add to the second combo box, try using a textbox that the user can directly enter a value in.

HTH
Lightning
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top