checking dates with Active X calendar control

sonia
02-11-2004, 03:19 AM
hi can anyone help me

i am using Microsoft Access 97, i am coding with visual basic editor, i have a form which has a Active X Calendar control.. 2 command buttons (which represent DayFrom and DayTo), and 2 textboxes, basically when the user clicks on a day on the calendar and then clicks on the command buttons DayFrom and DayTo the date is updated in the textboxes..

i have another textbox on the form and i am finding difficulty when i want the compare the two dates (that are in the two other textboxes) that are being selected so that i will get a day difference between them and that it also automatically deducts saturdays and sunday

anyone one can help me... would really appreciate it..thanks...

thingimijig
02-11-2004, 03:52 AM
something like this?

Dim date1 As Date, date2 As Date, i As Integer, x As Integer, count As Integer

date1 = Text1.Text 'the dates are already in the textboxes you say.
date2 = Text2.Text

x = DateDiff("d", date1, date2) 'find how many days for the loop

For i = 1 To x 'x is the actual last date so put x - 1 if you want it beetween the dates
Select Case Weekday(DateAdd("d", i, date1)) 'get the weekday number
Case 2 To 6 'find monday to friday
count = count + 1 'add to the count
End Select
Next i

MsgBox count


thingimijig.

sonia
02-11-2004, 07:21 AM
hi thanks for your help...
i have been playing around with the code since you gave it to me, i am having a problem though cause for some reason when i am giving the dates 9/01/2004 till 30/01/2004 it is giving me that there r 15 days and not 16...

can u help me.. its either giving me one day less or one day extra..



something like this?

Dim date1 As Date, date2 As Date, i As Integer, x As Integer, count As Integer

date1 = Text1.Text 'the dates are already in the textboxes you say.
date2 = Text2.Text

x = DateDiff("d", date1, date2) 'find how many days for the loop

For i = 1 To x 'x is the actual last date so put x - 1 if you want it beetween the dates
Select Case Weekday(DateAdd("d", i, date1)) 'get the weekday number
Case 2 To 6 'find monday to friday
count = count + 1 'add to the count
End Select
Next i

MsgBox count


thingimijig.

thingimijig
02-11-2004, 08:35 AM
i see, well it depends on how you want to count them.
if you want to include the first date aswell do this.

change

For i = 1 To x

to

For i = 0 To x


thingimijig.

sonia
02-12-2004, 01:52 AM
just wanted to say thanks loads.. i really appreciate ur help.. tell u t truth i kind of feel stupied that it didnt pass through my head to start the count from 0 to x... once again thanks loads... take care ..sonia..;)

i see, well it depends on how you want to count them.
if you want to include the first date aswell do this.

change

For i = 1 To x

to

For i = 0 To x


thingimijig.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum