Populate subform new records with dates

T

thinfrog4

Hi,

I have a Form in which an end user can specify a Start Date and a number of
Days.

The desired output is that once the the above information has been entered,
new records will be created in a subform: one new record for each day, with
the date specifed in sequence.

For example, if the Start Date is 01/01/10 and No. of Days is 3, then 3
records will be created in the subform, with Delivery Dates of 01/01/10,
02/01/10 and 03/01/10.

Any help would be fantastic; I have tried a myriad of code and always seem
to fall down.

Kind regards,

Dave
 
P

Piet Linden

Hi,

I have a Form in which an end user can specify a Start Date and a number of
Days.

The desired output is that once the the above information has been entered,
new records will be created in a subform: one new record for each day, with
the date specifed in sequence.

For example, if the Start Date is 01/01/10 and No. of Days is 3, then 3
records will be created in the subform, with Delivery Dates of 01/01/10,
02/01/10 and 03/01/10.

Any help would be fantastic; I have tried a myriad of code and always seem
to fall down.

Kind regards,

Dave

untested code, but this should point you in the right direction

Sub CreateDateRecords(dtStart as date, intDaysToAdd as Integer)
dim rsSub as dao.recordset 'same as subform's recordsource...
dim intDays as integer

set rsSub = dbEngine(0)(0).OpenRecordset("SourceForSub", dbOpenTable,
dbAppendOnly)

'you might need to tweak the bounds of the For loop...
for intDays = 0 to intDaysToAdd
with rsSub
.AddNew
.Fields("TheDateField")=DateAdd("d",intDays, dtStart)
.update
end with
next intDays
rsSub

rssub.close
set rssub=nothing
end sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top