If I understand correctly, you want a user to enter a StartDate and an
EndDate into two textboxes on a form. You then want to insert records in a
table that correspond to the StartDate and EndDate, and every date in between.
1. To start with, create a new table (tbl_Numbers) with a single field
(lng_Number).
2. Insert 9 records into this table (0, 1, ..., 9)
3. Create a query (qry_Numbers) that looks like:
SELECT Hundreds.lng_Number * 100 + Tens.lng_Number * 10 + Ones.lng_Number as
lng_Number
FROM tbl_Numbers as Hundreds,
tbl_Numbers as Tens,
tbl_Numbers as Ones
This will create a list of numbers from 1 to 999 (almost 3 years).
4. Next, create an Append query (qry_InsertDates) that looks something like:
PARAMETERS [StartDate] DateTime, [EndDate] DateTime;
INSERT INTO yourTable (DateField)
SELECT DateAdd("d",[lngNumber],[StartDate]) AS Expr1
FROM qry_Numbers
WHERE (((DateAdd("d",[lngNumber],[StartDate]))<=[EndDate]));
5. Finally, create a command button (cmd_InsertDates) on your form. In the
Click event of this command button, enter code similar to the following:
Private Sub cmd_InsertDates_Click
Dim qdf as dao.querydef
On Error goto InsertDatesError
'make sure the start and end date textboxes have valid dates
if len(me.txt_StartDate & "") = 0 then
msgbox "Enter a start date"
me.txt_StartDate.setfocus
exit sub
elseif len(me.txt_EndDate & "") = 0 then
msgbox "Enter a end date"
me.txt_EndDate.setfocus
exit sub
endif
Set qdf = currentdb.querydefs("qry_InsertDates")
qdf.parameters(0) = me.txt_StartDate
qdf.parameters(1) = me.txt_EndDate
qdf.execute dbfailonerror
set qdf = nothing
exit sub
InsertDatesError:
msgbox "error encountered, check the immediate window
debug.print err.number, err.description
End sub
I seriously doubt that this is exactly what you want. You probably want to
associate these dates with some other field as well, but this should give you
the general idea.
--
HTH
Dale
email address is invalid
Please reply to newsgroup only.
igorin said:
Hello,
I need to have a query that adds the values between (and including) two
input dates (which will be provided by the user).
This query will go into a Form where the user will be able to view this
information for the date range he desires. The user should be able to input
the desired date range into text boxes. Then the information for the rest of
the field text boxes should populate with the requested totals.
If my presentation of the issue is not clear, please, let me know and I will
try to clear any doubts.
Thank you very mcuh for the help.