VB Loop to Execute a Query

dmarek

New Member
Joined
Mar 26, 2010
Messages
21
What I'm trying to do (and figure out if it is possible, though I imagine it is) is execute a query repeatedly for a date range that is incrementally increased to a cap.

I can't just link my table to date table because of the way the database was built (not by me) forces me to use 2 date fields with criteria based off my date of which neither can be the exact date of my date. So to run for a range of dates I would physically have to change the date at the moment.

So what I'd like to do is have a VB code or some command that would run my query for Date A then do Date A +1, looping until it got to Date X (my end date).

Any help would be appreciated. If I need to go into more detail on how the table is setup let me know.

Thanks
 
I am getting an SQL error when trying to run the query (the 2nd version you did). Says SQL0418N A statement contains a use of parameter marker that is not valid.

Any thoughts?
 
Upvote 0

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
When I Google "SQL0418N" I see it's a DB2 error. So that means you're passing the append-query SQL directly to DB2 through some link, and DB2 doesn't like [DateParm] or Format$([DateParm],mm/dd/yyyy) which is Access language.

Go with my first way, since it worked. But if you ever have to change the SQL, you have to change it by hand in the code...
 
Upvote 0

Forum statistics

Threads
1,224,506
Messages
6,179,158
Members
452,892
Latest member
yadavagiri

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