We help IT Professionals succeed at work.

on
344 Views
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
Else  ' Otherwise simply return the calculated date
GetNearestTuesday = dtTemp
End If

End Function

Comment
Watch Question
CERTIFIED EXPERT
Top Expert 2016
Commented:
This problem has been solved!
###### Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

Deciding to stick with EE.

Mohamed Asif

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant