Access VBA test if today is past a certain date

Murray Brown
Murray Brown used Ask the Experts™
on
Hi. I want touse Access VBA code to check if today is past a certain date that I have specified
Will the following work?

        Dim oDate as date

        oDate = "31 Dec 2019"
       
        If DateDiff("d", oDate, Now()) >= 0 Then
            MsgBox "Your 30-day  trial period has expired.
        End If
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Hardware Tester and Debugger
Commented:
Hi there! :)

Try this instead!

Sub Example()


If DateDiff("d", Date, 2019 / 12 / 31) > 30 Then 
     MsgBox ("Your 30-day trial period has expired.")
Else
     MsgBox ("Your 30-day trial period has not expired.")
End If

End Sub

Open in new window

NorieAnalyst Assistant
Commented:
This will check if the current date is more than 30 days after the specified date.
Dim oDate as date

        oDate = DateSerial(2019, 12, 31)
       
        If DateDiff("d", oDate, Now()) > 30 Then
            MsgBox "Your 30-day  trial period has expired.
        End If

Open in new window

HuaMin ChenProblem resolver

Commented:
Use way like (in Access)

    If Me.dueDateTxt < Me.ShippedDate Then
    If CDate(startDate) < CDate(endDate) Then        
    If Format(startDate, "mm/dd/yyyy") < Format(endDate, "mm/dd/yyyy") Then
    If DateDiff(d, startDate, endDate) > 0 Then

Open in new window

   
to compare dates.
Murray BrownASP.net/VBA/VSTO Developer

Author

Commented:
thanks very much

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial