Need VBA help running a query with criteria based on text box.

MCTampa

Board Regular
Joined
Apr 14, 2016
Messages
97
I have a text box on a form called Text322.
I want enter multiple resort codes in the box and have them serve as the criteria for the RESX column in query 26 - Custom Report.
When I enter a single resort code such as BEE and have the criteria for RESX as [Forms]![Controls]![Text322].[Text] it woks fine.
However when I enter multiple codes such as BEE and SGJ, it returns nothing.

From doing a lot of reading, I understand that I need to write a VBA code to accomplish this. However I am struggling and getting no where.

What do I need to write to transform the values in my unbound text box from BEE, SGJ to "BEE" or "SGJ" in the criteria field of my query.

Thanks,
Mike
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Instead of a textbox, use a table.
enter your codes into the table,the query joins this table to the main data table to pull the records of those codes in the list.
 
Upvote 0
Continuous form.
(Access basics. Use the form wizard.)
 
Last edited:
Upvote 0
Thank you - when I created a table with one cell for on resort ID it worked.
However when I added resort ID's to that cell, it did not work.

I then created multiple cells and tried using the following as my criteria:

[Forms]![Table1]![Resort ID].[Text] Or [Forms]![Table1]![Resort ID 2].[Text] Or [Forms]![Table1]![Resort ID 3].[Text]

However this still did not work.
Should I be using one cell and entering multiple codes or have one code per cell?
 
Upvote 0
multiple values in a single field (Access doesn't have 'cells' per se) is a design approach that should be avoided in almost every situation. Only once in decades of working in Access have I ever seen a case where it was the best solution. lf you must, I think you would have to build your sql in code and concatenate the parts (at least SELECT, WHERE) together, using the IN operator e.g.
WHERE SomeField IN (code1, code2, code3). However, you'd have to ensure the delimiter was a comma and the textbox values were input properly.

You created a table, but did you still put multiple values in one field? This is unclear
However when I added resort ID's to that cell
You could use a continuous form as suggested, but what I didn't get from that is how it would help you feed a single query field with multiple criteria.

How many possible values need to be provided? You might benefit best from a search form.
Maybe like http://allenbrowne.com/ser-62.html
 
Upvote 0

Forum statistics

Threads
1,214,923
Messages
6,122,286
Members
449,076
Latest member
kenyanscott

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