Passing an InputBox value to a query?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

Is it possible to pass an InputBox value to a query?

1) as Criteria?

and/or

2) as the info to Update in the the Update line or an update query

Thanks
 
Yes, but we normally call these Parameter queries

1. To get a query to run and return a subset of results based on a
parameter, or mulitple parameters that you pass at query run-time, go to the
criteria line of the field you want to query and type something like: [Enter
value]

2. When you run the query, it will pop-up an inputbox that says "Enter
Value:" and when you respond to that it will restrict the query to those
records that match your criteria.

3. If you want to be a little more creative, you could filter a text field
to return all values that start with the string you enter. To do that, you
would set the criteria to: Like [Enter Value] & "*"
With this entry, it will return all the records if you just hit enter when
the combo box comes up, or only those records that have the same sequence of
characters at the beginning of the field.

4. To improve on this, and make sure that there will not be a datatype
mismatch between your data field and the parameter you want to enter, you
need to actually define the parameter you want to pass. To do this, right
click on the gray portion of the query grid and select the Parmeters option.
Under the Parameter enter the the same thing you placed in the criteria line
that was within the brackets. In my example, I would enter: [Enter Value]
Then select the data type that corresponds to the data field. When you run
the query, if the value you enter is not of the type that you selected, you
will get an error message and it will take you back to the parameter input
box.

5. To create an update query, you would do the same type of thing. My
example below would update Field2 to the [New Value] where the value of
Field1 is equal to some other value.

UPDATE myTable
Set [Field2] = [New Value]
WHERE [Field1] = [Update criteria]

HTH
Dale
 

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

Back
Top