I'm creating a area where when a date is entered to a date field, it asks a question, what I need this to do, is when the user clicks yes it runs a different calculation and when no is answered it runs a different caluclation, how would this be done. I have this code here, that a user gave me..
Private Sub DayWorkComplete_BeforeUpdate(Cancel As Integer)
If MsgBox("Is displayed date piror to current date?", 52, "Answer the question, bro") = vbYes Then
' Do yes
Else
' Do No
End If
End Sub
How would I make this work if the user click yes and wanted to run this code
Function GetNearestTuesday(dt As Date) As Date
Dim intWeekDay As Integer
Dim dtTemp As Date
Select Case Weekday(dt)
Case 3 ' Tuesday is day 3, so nearest Tuseday is the date passed to the function
dtTemp = dt
Case Is < 3 ' Date calculation for Sunday or Monday
dtTemp = DateAdd("d", 3 - Weekday(dt), dt)
Case Is > 3 ' Date calculation for other weekdays
dtTemp = DateAdd("d", 10 - Weekday(dt), dt)
End Select
'If the calculated nearest tuesday is in the holiday table, add 7 days
' **** Note -- You need to adjust the following statement to use the correct table and field names ***
If DCount("*", "tblHolidays", "Format([HolidayDate],'mm\/dd\/yyyy') = '" & Format(dtTemp, "mm\/dd\/yyyy") & "'") > 0 Then
GetNearestTuesday = DateAdd("d", 7, dtTemp)
Else ' Otherwise simply return the calculated date
GetNearestTuesday = dtTemp
End If
End Function