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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Command Button Custom Query?

Status
Not open for further replies.

HiAspire

Technical User
Oct 17, 2002
10
This maybe quite simple, I'm not sure. Don't do a ton of Access programming and have done something similar with a report before but couldn't locate that old code. This example isn't quite the situation but describes a similar sceanrio I'm trying to achieve.

Say I have a query in Access that shows all projects for every employee or rep based on active status. I can create a command button on a form which will open that general Query for me to see all of the active projects for all employee/reps. For example:

Dim stDocName As String
stDocName = "All Active Projects"
DoCmd.OpenQuery stDocName, acNormal, acEdit

On this form there is a field for the employee/rep associated with each project record. Hundreds of records, dozens of different employee/reps. Each record has one person listed as responsible for it.

What I really want to do is put that Run Query button next to the field on the form with someone's name on it, and have that query be personalized to only show me the records which have that employee/rep associated with them.

Seems simple enough, but I'm a little rusty getting back into it. Can criteria perameters be passed to the general query in that OpenQuery command based on the value of the current record in the form?

I believe the OpenReport command has a "Where Condition" associated with it to filter the results. Can something similar be done with opening a query?
 
Why don't you set the form fields as criteria expression within your query.

ex - open the query in design mode, and in the employee field's criteria put: Forms!YourForm!EmployeeField

Now when you use the OpenQuery action of the DoCmd object, it will be limited to the employee listed on the form.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top