Making sure a date falls on a Saturday (1 Viewer)

BukHix

Registered User.
Local time
Today, 14:16
Joined
Feb 21, 2002
Messages
379
I have a text box where a date is entered. Is there a way to make sure that the date entered is allways a Saturday?
 

Alexandre

Registered User.
Local time
Tomorrow, 01:16
Joined
Feb 22, 2001
Messages
794
Code:
Function IsSaturday(dtMyDate As Date) As Boolean
 IsSaturday = (Weekday(dtMyDate) = vbSaturday)
End Function

Alex
 

BukHix

Registered User.
Local time
Today, 14:16
Joined
Feb 21, 2002
Messages
379
Thanks Alex,

How do I use that with my sub?
Code:
Private Sub WeekEnding_Exit(cancel As Integer)
' Quick check on the date to keep acceptable range within 14 days.
    If WeekEnding > Date + 14 Or WeekEnding < Date - 14 Then
        MsgBox "The date is out of range", vbExclamation, "Entry Error"
        cancel = True
        WeekEnding.SelStart = 0
        WeekEnding.SelLength = Len(WeekEnding.Text)
    End If
End Sub
 

Alexandre

Registered User.
Local time
Tomorrow, 01:16
Joined
Feb 22, 2001
Messages
794
Tal..euh, BukHik

I cannot answer you since I do not know what you want to do upon testing that date. However, this is how to use the function:

If Not IsSaturday(WeekEnding) then msgbox "The date you entered is not a Saturday"

Alex
 

BukHix

Registered User.
Local time
Today, 14:16
Joined
Feb 21, 2002
Messages
379
Thanks again. This is how it ended up looking:

Code:
' Quick check on the date to keep acceptable range within 14 days.
    If WeekEnding > Date + 14 Or WeekEnding < Date - 14 Then
        MsgBox "The date is out of range", vbExclamation, "Entry Error"
        cancel = True
        WeekEnding.SelStart = 0
        WeekEnding.SelLength = Len(WeekEnding.Text)
    End If
    
    If Not IsSaturday(WeekEnding) Then
        MsgBox "The date you entered is not a Saturday", vbExclamation, "Try Again"
        cancel = True
        WeekEnding.SelStart = 0
        WeekEnding.SelLength = Len(WeekEnding.Text)
    End If

Tal Buk
 
R

Rich

Guest
Can you replace this If WeekEnding > Date + 14 Or WeekEnding < Date - 14 Then
With this
If WeekEnding > Date + 14 < Date - 14 Then
 

Alexandre

Registered User.
Local time
Tomorrow, 01:16
Joined
Feb 22, 2001
Messages
794
Rich,

You cannot because:
#01/01/2000# < #01/02/2000# < #01/01/2000#
<=>
True < #01/01/2000#
<=>
-1 < 36527
<=>
True (!)

Alex
 
R

Rich

Guest
Thank Alex
Now my brain's ceased to function it's time to go and hang some wallpaper.
 

simongallop

Registered User.
Local time
Today, 19:16
Joined
Oct 17, 2000
Messages
611
To return the next Saturday from a date (MyDate)

MyDate = Me.txtDate
If Weekday(MyDate) = 7 then '7=Saturday
SatDate = MyDate
else
SatDate = MyDate + 7 - Weekday(MyDate)
End If
Me.txtDate = SatDate

HTH
 

raskew

AWF VIP
Local time
Today, 13:16
Joined
Jun 2, 2001
Messages
2,734
Another way:

? DateAdd("d", 8 - WeekDay(Date, vbSaturday), Date)
 

simongallop

Registered User.
Local time
Today, 19:16
Joined
Oct 17, 2000
Messages
611
Being brain dead, you can ignore the If statement as 7 - Weekday where date is already Saturday would = 0, therefore noe amendment to the date!!

So

SatDate = MyDate + 7 - Weekday(MyDate)
 

Users who are viewing this thread

Top Bottom