Results 1 to 4 of 4

Thread: SORTED** For..Next using dates from 2 DTPickers

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2000
    Posts
    350

    Question SORTED** For..Next using dates from 2 DTPickers

    I've written a system to book rooms and equipment for our lab/showroom.

    I'm using DayView from April16.co.uk which gives an MS Outlook style of diary thingy. But you still need to add the appointments to a database in code; the DayView then reflects the current day. So that's all simple so far.

    I've used a DTPicker to select the date for which a) an appointment is created and b) the user wants displayed.

    But THEN.......................

    We thought it would be nice to be able to create recurring appointments, like booking a room for 5 days for a course. I thought of using 2 DTPickers, and if date2 > date1 then do the appointment creation a number of times .

    TROUBLE IS (as far as I can see) VB compares dates only on the day of the month not the whole date. I'm using dd/mm/yyyy as my system short date format btw. Here's what happens...

    date1 = 21/10/2002
    date2 = 21/10/2002
    .... vb sees the dates as equal, only 1 appointment as expected

    date1 = 21/10/2002
    date2 = 22/10/2002
    ..... vb sees date2 > date1, loops in the for..next to make 2 appts

    date1 = 21/10/2002
    date2 = 06/11/2002
    ..... vb sees date2 < date1, no looping, 1 appt only
    ..... ie seems to compare the 6 and the 21

    date1 = 21/10/2002
    date2 = 23/11/2002
    ..... vb sees date2 > date1, loops to make lots of appts
    ..... ie it sees 23>21 and in fact loops all the way from 21/10 to 31/10 then to 23/11 correctly.

    Help!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    Anyone got some ideas please?

    Here's some test code...

    VB Code:
    1. Private Sub CommandTest_Click()
    2. 'Add 2 x DTPickers which are in MSWindows Common Controls
    3.  
    4. Dim dayCount As Date
    5.  
    6. Debug.Print DateValue(dt1.Value)
    7. Debug.Print DateValue(dt2.Value)
    8.  
    9. If DateValue(dt2.Value) > DateValue(dt1.Value) Then
    10.     For dayCount = DateValue(dt1.Value) To DateValue(dt2.Value)
    11.          Debug.Print "Appointment for " & dayCount
    12.     Next
    13.   Else
    14.     Debug.Print "Only 1 appt"
    15. End If
    16. End Sub
    Last edited by Jim Brown; Oct 21st, 2002 at 08:02 AM.
    .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width