We help IT Professionals succeed at work.

Question about Ask Yes/No

Cyprexx IT
Cyprexx IT asked
on
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



Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2016

Commented:

try this

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
     GetNearestTuesday(Me.DayWorkComplete)

 Else
    ' Do No
 End If

End Sub


CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2013

Commented:
What kind of function are you planning to run if the user selects "no"?

If it is a similar function (a simple calculation), you may want to move your code to the AfterUpdate event.

The before update event is generally used for validating user input, and rolling back changes if data entry requirements are not met.

Author

Commented:
I made a screen cast, maybe this will help!





CyprexxIT-519916.flv
CERTIFIED EXPERT
Top Expert 2016
Commented:

Private Sub DayWorkComplete_BeforeUpdate(Cancel As Integer)

 If MsgBox("Is displayed date piror to current date?", 52, "Answer the question, bro") = vbYes Then
   
 ' if the answer is Yes  run this code
     
              GetNearestTuesday(Me.DayWorkComplete)
 Else
 
   ' if the answer is NO

           'place here the codes that you like to run

 End If

End Sub

Author

Commented:
That's another problem I'm running into!

Explore More ContentExplore courses, solutions, and other research materials related to this topic.