View Full Version : Problem with my query (WARNING NEWBIE)


Rook
09-13-2001, 03:07 PM
*** Warning ***
I've very new to Access and dont know it that well. I've setup a query that asks a question to query the records. How hard will it be to expand the criteria so that after the number in the query is put it that if the number isn't in the table (or NULL) that it prompts a message saying so. I've been using the Expression Builder with little luck.

Any help would be greatfully appreciated.

jwindon
09-13-2001, 04:49 PM
There is a simple way to allow the user to ONLY select items that ARE in your table. It is done through the use of a "combo box" that is not bound to any table or query, but acts only as a means of "selecting" your criteria.

To do this:
Create a new form, but don't base it off anything. In design view, use your toolbox icon to find the "combobox". Drag one down on your form. A wizard will start and ask you questions about what tables, values, etc. you want for your combo. Say you want the EmployeeName from the TBL_EMPLOYEES in your database to be the things listed in your "search". For this example I would choose TBL_EMPLOYEES and the next screen asks for fields to show. I want to show the EmployeeName, but you probably have an EmployeeID field in your table that should show too. Once you finish the wizard, right click on the combobox and Goto the data tab and find LimitToList: Select Yes. After that goto view, form and try out the combo box. It should show you those fields you selected.

Now, to make the query work off of that box...

Open your query in design view. Where you previously put [Enter Employee Name:] you will type this:

Forms!NameOfTheFormYouJustMade![NameOfTheComboBoxYouJustMade]

To try it out, leave your form open and run the query. If you selected Bill in your combo, the query will return Bill. Now to get it to work automatically after you select a name will require an Event.

In your form, right click on your combobox and goto the tab Events. Find the AfterUpdate and click the build button. Select Code Builder (don't be afraid, you'll love this later). Between the lines of Private Function...and End put this code

DoCmd.OpenQuery "yourqueryname" , acNormal, acEdit

Close the Visual Basic window and open your form in form view again. Try it out. When you change your selection to something, the query should run based on that selection.

Give it a try. I hope that's what you wanted. Let me know if you need help. I'll be out of town this weekend, but you can email me anytime between now and Sat morning at MyAvonGirl@aol.com