473,385 Members | 1,564 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Help with Do...Loop command using dates as parameter

I have a form that requires a start date and an end date as input for
the parameters then runs the form which open queries which are designed
to populate certain tables. As it stands now, i can only run the form
one month at a time, so i would enter the first of the month, say
01/01/2002 and the end of the month 01/31/2002 and it would run the
form with january data. If i enter a range of dates from say 01/01/2002
to 06/30/2002, it will only run the query based on the end date being
june 30th and it will ignore the start date. therefore the tables will
only be populated with june data, not january, february, etc. as
expressed by the parameters.
Therefore, what i need to do is create a loop function that will run
the form month by month until all the queries have been run and all the
tables have been populated. I have an idea how to do this, but i can't
seem to get the loop statement correct. it's still only running the
form for only one month based on the end date. is there anyone that can
point me in the right direction? thanks.
Here is pretty much the code that i have thus far:

Dim intDuration As Integer
Dim strInterval As String
intDuration = 1
strInterval = "m"

DoCmd.SetWarnings False
Do Until 'this is where i want it to loop the statements month by month
CalcCum "qryCalcCumYTDBM"
DoCmd.OpenQuery "qryYTDReturnsBM", acNormal, acEdit
CalcCum "qryCalcCumQBM"
DoCmd.OpenQuery "qryQReturnsBM", acNormal, acEdit
CalcCum "qryCalcCum6mBM"
DoCmd.OpenQuery "qry6MReturnsBM", acNormal, acEdit
CalcCum "qryCalcCum12mBM"
DoCmd.OpenQuery "qry12MReturnsBM", acNormal, acEdit
CalcCum "qryCalcCumCumBM"
DoCmd.OpenQuery "qryCumReturnsBM", acNormal, acEdit
CalcCum "qryCalcCum24mBM"
DoCmd.OpenQuery "qry24MReturnsBM", acNormal, acEdit
Loop
MsgBox "All Calculations Completed"

Nov 13 '05 #1
4 3298
I have created an expression which, to me, looks like it should work.
but if i enter the dates january to march, instead of running those 3
months thru the queries, it runs the same month (march) 3 times. here
is the code if anyone could give me some suggestions on what to fix.
thanks.

Dim StartDate As Date
Dim strInterval As String
Dim Number As Integer
strInterval = "m"
StartDate = Me.Form!txtFrom
EndDate = Me.Form!txtTo
Number = 1

Do While StartDate <= EndDate
CalcCum "qryCalcCumYTDBM"
DoCmd.OpenQuery "qryYTDReturnsBM", acNormal, acEdit
etc.,
StartDate = DateAdd(strInterval, Number, StartDate)
Loop
MsgBox "All Calculations Completed"

Nov 13 '05 #2
Something's missing here... Does your query point to your form to grab
this value that you're updating? Of course, there's no way for it to
"see" this value, because it's in CODE and not in a control on your
form... you could create an unbound textbox on your form, slap the
value into it, and then maybe your code would work.

Do While StartDate <= EndDate
CalcCum "qryCalcCumYTDBM" <== is "CalcCum" a FUNCTION you wrote?
'--are you passing your textbox value to this? How?
DoCmd.OpenQuery "qryYTDReturnsBM", acNormal, acEdit

etc.,
StartDate = DateAdd(strInterval, Number, StartDate)
Loop

if qryYTDReturnsBM has a parameter that points at your open form, then
this should work.

SELECT... MyTable!Price * Forms!MyOpenForm!txtMyQty As MyExpression
FROM MyTable
WHERE MyTable!InvoiceNo=Forms!MyOpenForm!InvoiceNo

might work.

Nov 13 '05 #3
thanks for thee suggestion, but the query runs off of a table, not a
form (i don't know if this makes a difference). the value for january
should be picked up from the table and ran thru the queries, then the
value from february, then march, and so on. i figured there was no need
to create an unbound text box because the date parameters have already
been input and the return values (if that is the value you are
referring to entering) can't be input because there are many values for
each date due to the fact that there are many funds. any suggestions?
thanks.

Nov 13 '05 #4
the problems with the SELECT expression is I keep receiving an error
message "Compile Error; Expected:Case". any solutions to fix this in
the code?

Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: jdph40 | last post by:
I have a form in Access 97 on which I have an unbound list box filled with our employees names from tblEmployees. When you select an employee's name and click a button, the following code is run...
9
by: Dom Boyce | last post by:
Hi First up, I am using MS Access 2002. I have a database which records analyst rating changes for a list of companies on a daily basis. Unfortunately, the database has been set up (by my...
0
by: Edwinah63 | last post by:
Hi guys, i am not new to vb6, but a mere tyro in vb.net what i want to do is the following open transaction build an ADODB command object using parameters execute it build another command...
12
by: colincolehour | last post by:
I am new to Python and am working on my first program. I am trying to compare a date I found on a website to todays date. The problem I have is the website only shows 3 letter month name and the...
7
by: Siv | last post by:
Hi, I have a stored procedure that I want to execute and then wait in a loop showing a timer whilst it completes and then carry on once I get notification that it has completed. The main reason...
3
by: Matthew Warren | last post by:
I have the following piece of code, taken from a bigger module, that even as I was writing I _knew_ there were better ways of doing it, using a parser or somesuch at least, but learning how wasn't...
15
by: Jay | last post by:
I have a multi threaded VB.NET application (4 threads) that I use to send text messages to many, many employees via system.timer at a 5 second interval. Basically, I look in a SQL table (queue) to...
2
by: Bill | last post by:
I have a 200 record database that includes a date/time field, AnnivDate, for a wedding anniversary. AnnivDate has nulls and some incorrect year data. I have been creating the Access database...
2
by: fniles | last post by:
I am using .Net 2003 and querying a SQL Server 2000 database. I read the database in a loop, but on every iteration I set the SQLCommand to new, set it, execute it, dispose and set it to nothing....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.