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
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.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.