|
-
Oct 21st, 2002, 07:30 AM
#1
Thread Starter
Hyperactive Member
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:
Private Sub CommandTest_Click()
'Add 2 x DTPickers which are in MSWindows Common Controls
Dim dayCount As Date
Debug.Print DateValue(dt1.Value)
Debug.Print DateValue(dt2.Value)
If DateValue(dt2.Value) > DateValue(dt1.Value) Then
For dayCount = DateValue(dt1.Value) To DateValue(dt2.Value)
Debug.Print "Appointment for " & dayCount
Next
Else
Debug.Print "Only 1 appt"
End If
End Sub
Last edited by Jim Brown; Oct 21st, 2002 at 08:02 AM.
.
-
Oct 21st, 2002, 07:34 AM
#2
PowerPoster
You may use DateDiff VB function to get results in Days, Weeks, etc...
-
Oct 21st, 2002, 07:42 AM
#3
Frenzied Member
If vb is comparing the 6 and the 21 then it is comparing strings.
For dates you can use the DateDiff function
try this in your form
VB Code:
date1 = 21/10/2002
date2 = 06/11/2002
Debug.Print DateDiff("d",date1,date2)
Code:
If Question = Incomplete Then
AnswerNextOne
Else
ReplyIfKnown
End If
cu Swatty
-
Oct 21st, 2002, 07:59 AM
#4
Thread Starter
Hyperactive Member
Thanks for your help but using DateDiff I got the same problem, until I realised the DateValue was causing (I think) the d/m/y to become m/d/y or something and it was getting all confuzled.
So I took the DateValue out of my original code and out of my testcode using DateDiff and it's sorted.
Last edited by Jim Brown; Oct 21st, 2002 at 08:03 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|