D
Derek Wittman
Good afternoon,
I have up to and including 5 dates that I need to compare to one another. I
was thinking I had a few options on how to make this work. I thought I could
compare date 2 with date 1, then date 3 with date 2, and so on, but this will
not catch my users if they make date 3 = date 1...
So, I need to actually somehow do all 10 iterations (5 Combinations, taken 2
at a time for all you statisticians out there!). Unfortunately, my code is a
bit on the messy side, aside from Doug Steele's assistance earlier. Aside
from checking the dates against each other, my number of dates to compare can
be from 1 to 5, and there are times when a date must be after an associate's
anniversary date. (on 3 years, 8 years, 15 years, and 20 years, associates
get an additional vacation week, but only AFTER their anniversary date).
Associates are also permitted (dateadd function) to take a vacation week in
the week where their anniversary falls.
It's an extremely (for me, anyway) ugly bit of code, so please watch the
wordwraps as well. I do appreciate any assistance that may come my way.
Private Sub cmdSubmit_Click()
Dim datecheck As Date
Dim datecount As Integer
Dim nullcount As Integer
Dim nullchecker As Integer
nullcount = 0
datecount = 0
datecheck = DateAdd("d", -6, Month(DLookup("[AssocDOH]", "tblAssociates",
"[AssocID#] = Forms!frmMain.txtID")) & "/" & Day(DLookup("[AssocDOH]",
"tblAssociates", "[AssocID#] = Forms!frmMain.txtID")) & "/06")
If Len(Forms!frmVacEntry.txt1stweek & "") > 0 Then
nullcount = nullcount + 1
If datecheck < DateValue(txt1stweek) Then datecount = datecount + 1
End If
If Len(Forms!frmVacEntry.txt2ndweek & "") > 0 Then
nullcount = nullcount + 1
If datecheck < DateValue(txt2ndweek) Then datecount = datecount + 1
End If
If Len(Forms!frmVacEntry.txt3rdweek & "") > 0 Then
nullcount = nullcount + 1
If datecheck < DateValue(txt3rdweek) Then datecount = datecount + 1
End If
If Len(Forms!frmVacEntry.txt4thweek & "") > 0 Then
nullcount = nullcount + 1
If datecheck < DateValue(txt4thweek) Then datecount = datecount + 1
End If
If Len(Forms!frmVacEntry.txt5thweek & "") > 0 Then
nullcount = nullcount + 1
If datecheck < DateValue(txt5thweek) Then datecount = datecount + 1
End If
nullchecker = earnedweeks() - nullcount
Select Case nullchecker
Case 0
If Nz(txtAddlwks, 0) > 0 Then MsgBox "Checking your anniversary
date...", , "You're almost done!"
If txtAddlwks = 1 Then
If datecount = 0 Then MsgBox "You must select 1 of your weeks
after your anniversary date", vbOKOnly, "Try again"
If datecount = 1 Then
MsgBox "Congratulations! Your vacation will be scheduled.",
vbOKOnly, "Congrats!"
MsgBox "You will not be guaranteed your scheduled time off if
you bid into a new shift or section", , "DISCLAIMER"
End If
End If
Case 1
MsgBox "You have 1 more week to use. Please complete the form",
vbOKOnly, "Try Again"
If txtAddlwks = 1 Then
If datecount = 0 Then MsgBox "You must select 1 of your weeks after
your anniversary date", vbOKOnly, "Try again"
End If
Case Else
MsgBox "You have " & nullchecker & " more weeks to use. Please
complete the form", vbOKOnly, "Try Again"
If txtAddlwks = 1 Then
If datecount = 0 Then MsgBox "You must select 1 of your weeks after
your anniversary date", vbOKOnly, "Try again"
End If
End Select
End Sub
Thank you very much!
DW
I have up to and including 5 dates that I need to compare to one another. I
was thinking I had a few options on how to make this work. I thought I could
compare date 2 with date 1, then date 3 with date 2, and so on, but this will
not catch my users if they make date 3 = date 1...
So, I need to actually somehow do all 10 iterations (5 Combinations, taken 2
at a time for all you statisticians out there!). Unfortunately, my code is a
bit on the messy side, aside from Doug Steele's assistance earlier. Aside
from checking the dates against each other, my number of dates to compare can
be from 1 to 5, and there are times when a date must be after an associate's
anniversary date. (on 3 years, 8 years, 15 years, and 20 years, associates
get an additional vacation week, but only AFTER their anniversary date).
Associates are also permitted (dateadd function) to take a vacation week in
the week where their anniversary falls.
It's an extremely (for me, anyway) ugly bit of code, so please watch the
wordwraps as well. I do appreciate any assistance that may come my way.
Private Sub cmdSubmit_Click()
Dim datecheck As Date
Dim datecount As Integer
Dim nullcount As Integer
Dim nullchecker As Integer
nullcount = 0
datecount = 0
datecheck = DateAdd("d", -6, Month(DLookup("[AssocDOH]", "tblAssociates",
"[AssocID#] = Forms!frmMain.txtID")) & "/" & Day(DLookup("[AssocDOH]",
"tblAssociates", "[AssocID#] = Forms!frmMain.txtID")) & "/06")
If Len(Forms!frmVacEntry.txt1stweek & "") > 0 Then
nullcount = nullcount + 1
If datecheck < DateValue(txt1stweek) Then datecount = datecount + 1
End If
If Len(Forms!frmVacEntry.txt2ndweek & "") > 0 Then
nullcount = nullcount + 1
If datecheck < DateValue(txt2ndweek) Then datecount = datecount + 1
End If
If Len(Forms!frmVacEntry.txt3rdweek & "") > 0 Then
nullcount = nullcount + 1
If datecheck < DateValue(txt3rdweek) Then datecount = datecount + 1
End If
If Len(Forms!frmVacEntry.txt4thweek & "") > 0 Then
nullcount = nullcount + 1
If datecheck < DateValue(txt4thweek) Then datecount = datecount + 1
End If
If Len(Forms!frmVacEntry.txt5thweek & "") > 0 Then
nullcount = nullcount + 1
If datecheck < DateValue(txt5thweek) Then datecount = datecount + 1
End If
nullchecker = earnedweeks() - nullcount
Select Case nullchecker
Case 0
If Nz(txtAddlwks, 0) > 0 Then MsgBox "Checking your anniversary
date...", , "You're almost done!"
If txtAddlwks = 1 Then
If datecount = 0 Then MsgBox "You must select 1 of your weeks
after your anniversary date", vbOKOnly, "Try again"
If datecount = 1 Then
MsgBox "Congratulations! Your vacation will be scheduled.",
vbOKOnly, "Congrats!"
MsgBox "You will not be guaranteed your scheduled time off if
you bid into a new shift or section", , "DISCLAIMER"
End If
End If
Case 1
MsgBox "You have 1 more week to use. Please complete the form",
vbOKOnly, "Try Again"
If txtAddlwks = 1 Then
If datecount = 0 Then MsgBox "You must select 1 of your weeks after
your anniversary date", vbOKOnly, "Try again"
End If
Case Else
MsgBox "You have " & nullchecker & " more weeks to use. Please
complete the form", vbOKOnly, "Try Again"
If txtAddlwks = 1 Then
If datecount = 0 Then MsgBox "You must select 1 of your weeks after
your anniversary date", vbOKOnly, "Try again"
End If
End Select
End Sub
Thank you very much!
DW