Loop through dates (1 Viewer)

Lizba

New member
Local time
Tomorrow, 01:21
Joined
Apr 29, 2010
Messages
9
Hi there
I have a form where someone books a room (Room 1) for x number of nights - from [DateIn] = 2010/04/28 to [DateOut] = 2010/05/02. I want to load this info to a table similar to this:

Room Date Customer
Room1 2010/04/28 Mr Jones
Room1 2010/04/29 Mr Jones
Room1 2010/04/30 Mr Jones
Room1 2010/05/01 Mr Jones

So I need to create a loop that will add a record for each date between DateIn and DateOut-1.

Can someone help me???
Lizba
 

chergh

blah
Local time
Today, 23:21
Joined
Jun 15, 2004
Messages
1,414
A guy at my work had an assignment very much like this when he was doing an access course at college. I didn't do his home work for him either.
 

Lizba

New member
Local time
Tomorrow, 01:21
Joined
Apr 29, 2010
Messages
9
Unfortunately its not an assignment! Nor am I at college! Its a genuine query for our company database.
 

raskew

AWF VIP
Local time
Today, 17:21
Joined
Jun 2, 2001
Messages
2,734
Hi -

This will provide a starting point. You'll probably want to convert the sub to a function:

Code:
Public Sub Jones(datein As Date, dateout As Date)
Do While datein < dateout
   Debug.Print datein
   datein = datein + 1
Loop
End Sub

Example:
Call Jones(#4/28/10#, #5/2/10#)
4/28/2010
4/29/2010
4/30/2010
5/1/2010


HTH - Bob
 

Users who are viewing this thread

Top Bottom