Avatar of al4629740
Flag for United States of America asked on

Loop months of the year in this code

I am trying to loop 3 months of the year into the code below.  How do I write this type of loop statement.  I am drawing a blank for some reason...

'How turn this into a loop where Var1 is a loop of January, February, March so that I get the total for all 3 months

select count(*) from table where Month = Var1
rec2.CursorLocation = adUseClient
rec2.Open (esql), conn, adOpenStatic, adLockOptimistic

Total = Total + rec.Fields(0)

Open in new window

Visual Basic Classic

Avatar of undefined
Last Comment

8/22/2022 - Mon

Does your table have a column named "month"?  If this is a new table, I should advise you to have column names that are different than database function names.

What type of column is "month" (numeric or text)?

Normally, I would create a Select statement that summed/counted the data for a date range, rather than executing three different Select statements.
select count(*) from table where Month Between 1 and 3

Open in new window


Month column is text.

What I need was a loop to go through specified months as mentioned in the question.  


Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.

select count(*)
from table
where Month = 'January'
or  Month = 'February'
or Month = ' March'
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy

No loop required, just the query

Thanks for the effort