Query with variable

  • Thread starter Thread starter SMERTZ
  • Start date Start date
S

SMERTZ

How do I create a query in design view with a variable? If I want the user
to type in a "LastName" from the Customers table when the query runs, how
can I set that up?

Thanks
 
How do I create a query in design view with a variable? If I want the user
to type in a "LastName" from the Customers table when the query runs, how
can I set that up?

Thanks

Use a Parameter Query: on the criteria line put

[Enter last name:]

or, better, create a little unbound form named frmCrit; put a Combo
Box on it selecting all the customer ID's and displaying their names;
for instance a query like

SELECT CustomerID, LastName & ", " & FirstName
FROM Customers
ORDER BY LastName, FirstName;

Create a Combo Box cboCustomer on frmCrit using this query; then use a
query criterion of

=Forms![frmCrit]![cboCustomer]

on the CustomerID field of your query.

John W. Vinson[MVP]
 
I like the unbound form idea!!


John Vinson said:
How do I create a query in design view with a variable? If I want the user
to type in a "LastName" from the Customers table when the query runs, how
can I set that up?

Thanks

Use a Parameter Query: on the criteria line put

[Enter last name:]

or, better, create a little unbound form named frmCrit; put a Combo
Box on it selecting all the customer ID's and displaying their names;
for instance a query like

SELECT CustomerID, LastName & ", " & FirstName
FROM Customers
ORDER BY LastName, FirstName;

Create a Combo Box cboCustomer on frmCrit using this query; then use a
query criterion of

=Forms![frmCrit]![cboCustomer]

on the CustomerID field of your query.

John W. Vinson[MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

How to create a bubble chart with more than 2 variables 0
Problem with jet database 3
query 1
Query with variable 4
Macro Variables 4
Query Performance 4
Queries 3
question about running a comparison query 2

Back
Top