How to put a conditional inside another conditional | Access VBA

by Henry Pinston   Last Updated October 20, 2019 05:26 AM

How can I add another conditional to the following conditional statement:

Private Sub Form_Timer()

Me.myTime = Now()
Me.dayText = Now()

    If TimeValue(Now()) = #3:00:00 PM# Then
        Call Button1_Click
        DoCmd.SetWarnings True
    End If
End Sub

The Form_Timer() triggers the button Button1 to click when the time is 3:00 pm in the textbox myTime.

But I also have a textbox called dayText that displays the current Day of the week.

I would like Button1 to be triggered only if the day is not Saturday or Sunday and the time is 3:00 pm.

So I am looking to do something like this:

If Me.dayText = #Saturday# or #Sunday# Then

    If TimeValue(Now()) = #3:00:00 PM# Then
    Call Button1_Click
    DoCmd.SetWarnings True

End If

End If

The 2 textboxes look like this:

enter image description here

Tags : vba ms-access


Answers 1


If your textbox dayText is date formatted (means have date value) then you can use following.

If Format(Me.dayText, "dddd") = "Saturday" Or Format(Me.dayText, "dddd") = "Sunday" Then
    If TimeValue(Now()) = #3:00:00 PM# Then
        Call Button1_Click
        DoCmd.SetWarnings True
    End If
End If
Harun24HR
Harun24HR
October 20, 2019 05:24 AM

Related Questions


Updated July 30, 2019 07:26 AM

Updated July 26, 2018 07:26 AM

Updated March 28, 2017 08:26 AM

Updated February 11, 2019 14:26 PM

Updated January 16, 2019 09:26 AM