text box to set query criteria

  • Thread starter Thread starter Michael Hanlon
  • Start date Start date
M

Michael Hanlon

Currently I am working on a database that has 10 tables all link by EMPID
field. I Have a macro that runs 10 query that transfers all the info on
employees to another database when then are transfer to our other office.
What I am looking for is a way to ask for the EMPID and apply it to all the
queries. Right now I have it asked for the empid field for every query. Can
the criteria for the query be done by code off of a form with a text box
that the user enter's the empid.

Any and all help would be great.

Thank You
mike
 
Sure can.

From the Help file:

For example, you could create a dialog box form named Customer Info with a
control for the CustomerID field. By entering a customer ID in the dialog
box, you could have the query return the correct customer's company name,
address, and city. To create this query, you'd do the following:

· Add the CustomerID field to the query design grid. In its Criteria cell,
enter the expression that tells Microsoft Access to refer to the Customer ID
control in the dialog box for the criteria values the query uses. In this
case, you'd enter the expression Forms![Customer Info]![CustomerID].
· Add to the query design grid the fields whose values you want returned
based on the CustomerID value: CompanyName, Address, and City fields.
 
You'll often get into a sticky situation if your text boxes have the
same names as the fields they are bound to (i.e. a textbox named
"EMPID" bound to the field "EMPID" in your table), because Access won't
always know if you are talking about the text box control named EMPID
or the field EMPID (which can sometimes have very different outcomes,
especially when dealing with queries). It's good practice to rename all
controls to something which indicates that they are controls.. i.e.
"txtEMPID" or "t_EMPID" to indicate that you are referring to the text
box control which is bound to the field EMPID.
 
Back
Top