Would like to run a query that is using a field in a table for it's criteria (1 Viewer)

Status
Not open for further replies.

AnsonniChu

New member
Local time
Today, 04:50
Joined
Jul 11, 2019
Messages
2
I am new and have very basic knowledge of programming.

So, I have a table that contains fields that is written in the same way as you would write in a criteria for a field in a query
(ex: the field would contain:
"1234 Or 1242"
or some date range:
"Between #06/23/2019# and #06/25/2019#").

I would like to setup an event that runs a query with the field in the table as the criteria and loop it so it runs the query for each line.

Please if someone can help me with this it is appreciated.
 

jdraw

Super Moderator
Staff member
Local time
Today, 07:50
Joined
Jan 23, 2006
Messages
15,361
Welcome.
Suggest you give us a little more info. You don't see fields in tables with value "1234 Or 1242".
Table name
Field name
Field value
An overview of what you are trying to accomplish in plain English.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 04:50
Joined
Oct 29, 2018
Messages
21,357
Hi. Welcome to the forum. The only thing I could think of at the moment is to use a "dummy" query and then modify its SQL adding the criteria from the table as you loop through it and run each one. You do this using a QueryDef object.
 

AnsonniChu

New member
Local time
Today, 04:50
Joined
Jul 11, 2019
Messages
2
Sorry I'll try to explain i have a table like below:

ID PromoDept Periods
1 1267 OR 1415 Between #06/23/2019# and #06/29/2019#
2 1536 OR 6538 OR 1415 Between #06/23/2019# and #06/25/2019#
3 2353 OR 2356 Between #06/26/2019# and #06/27/2019#
4 2366 OR 2356 Between #06/26/2019# and #06/27/2019#

And I would like to setup a macro that essentially looks at each line individually and use Field PromoDept as a criteria for a query. I attached an example database don't know if that would help?
 

Attachments

  • Example.accdb
    520 KB · Views: 182

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:50
Joined
May 7, 2009
Messages
19,169
see this demo and try to understand the code.
 

Attachments

  • Example.zip
    56.1 KB · Views: 239
Status
Not open for further replies.

Users who are viewing this thread

Top Bottom