how to add recordset between two date

J

Jon

Greeting,

I have a form which contains two text box. Text1 Start and text2 End. How to
make access input the all date between those two dates in one click in a
table??
 
A

Allen Browne

Jon said:
I have a form which contains two text box. Text1 Start and text2 End. How
to make access input the all date between those two dates in one click in
a table??

This sample code illustrates how to create records in tblDate.TheDate:

Function MakeDates(dtStart As Date, dtEnd As Date) As Long
Dim dt As Date
Dim rs As DAO.Recordset

Set rs = DBEngine(0)(0).OpenRecordset("tblDate")
With rs
For dt = dtStart To dtEnd
.AddNew
!TheDate = dt
.Update
Next
End With
rs.Close
Set rs = Nothing
End Function
 
A

Allen Browne

You could put the code into the Click event procedure of a command button,
instead of as a function.

Presumably you will use [Text1 Start] and [Text2 End] as the dates for the
loop.
 
G

ghost

Thanks Allen, but how to exclude Start Date & End date form the list??

Allen Browne said:
You could put the code into the Click event procedure of a command button,
instead of as a function.

Presumably you will use [Text1 Start] and [Text2 End] as the dates for the
loop.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Jon said:
Thank you Allen, but how to execute it by using command button
 
J

John Spencer

Well add 1 to start date and subtract one from end date when you pass the
dates to the function.

OR change the function to read

For dt = dtStart+1 to DtEnd-1

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
Thanks Allen, but how to exclude Start Date & End date form the list??

Allen Browne said:
You could put the code into the Click event procedure of a command button,
instead of as a function.

Presumably you will use [Text1 Start] and [Text2 End] as the dates for the
loop.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Jon said:
Thank you Allen, but how to execute it by using command button

:

I have a form which contains two text box. Text1 Start and text2 End.
How
to make access input the all date between those two dates in one click
in
a table??
This sample code illustrates how to create records in tblDate.TheDate:

Function MakeDates(dtStart As Date, dtEnd As Date) As Long
Dim dt As Date
Dim rs As DAO.Recordset

Set rs = DBEngine(0)(0).OpenRecordset("tblDate")
With rs
For dt = dtStart To dtEnd
.AddNew
!TheDate = dt
.Update
Next
End With
rs.Close
Set rs = Nothing
End Function
 

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