Passing data from form to perameter query

jtodd

Board Regular
Joined
Aug 4, 2014
Messages
194
I have a table with product , height, length, width,

Can I use a parameter query to search by all three Ie >50 <40 >20 or by any combination of these preferabley
from a form.
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Yes, but unless you're going to run the query by invoking the Execute method of the database object, I don't think you need a true parameter query. Just put [Height] in the query height field, [Length] in the length field and [Width] in the width field. If you put these on one criteria line, you will have to provide all three as it will function as AND condition. If each is on it's own line, it should function as an OR condition. Sometimes people build a Like condition around these criterial prompts but I don't see that being necessary based on what information you provided. You should also be able to preface the prompt with > such as >[Width]. If you're going to get more complicated than what I see here, such as allowing user to choose operator options such as <, >, = and Between, you're going to have to write code behind a form.
 
Upvote 0
1. Create 3 Text Boxes and a Command Button on the Form (myForm).
2. Change the Name property Value of the Text Boxes as xHeight, xLength and xWidth.
3. Open the Query in Design View.
4. Enter the following expression in Criteria Row of the Query under the Height Column:
Code:
>Forms!myForm![xHeight]
5. Enter similar expressions, with appropriate logical symbols, under Length & Width columns, in the same row and save the Query. Remember, when you write all expressions on the same row all the three conditions must be TRUE to get the output.
6. Change the Name Property of the Command Button as cmdRefresh.
7. Write the following VBA Code in the Click event procedure of the command Button.
Code:
Private Sub cmdRefresh_Click()
  Me.Refresh
End Sub
8. Save the Form and open it in Normal View, set the Text Boxes with appropriate values (don't type <, > symbols), click the Command Button.
9. Open the Query in normal view and check the result.
 
Upvote 0

Forum statistics

Threads
1,221,842
Messages
6,162,333
Members
451,760
Latest member
samue Thon Ajaladin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top