0

In excel, If I want a cell to autoupdate the date I use a variant of the following code:

TODAY() + MOD(DATE(2021,1,1) - TODAY(),90) - 90

That string will auto update every 90 days, What I need to do is convert this to a VBA function, which will be part of the onload function in a given form. I have tried

DATE() + (2 / 4 / 2021 - DATE()) Mod 90 - 90

Which obviously doesn't work. Any ideas out there on how to make this happen? The result of this needs to be used in a SQL Where statement. Now I could just hardcode the dates, as this does update every quarter, and then run a complicated if statement, but it seems the wrong way to do it.

Edited: I was informed I wasn't clear enough and reread it, and I guess I Am not.

I need this to be a variable in VBA in order to compare the date the application is run to a date stored in 4 different tables.

The idea is that 90 days from a set date, the front end has a search feature that should pull information from the requested table(s) at the users request.

So what I am trying to do is create a public variable that auto updates every 90 days in order to always keep this up to date, and not have to recode dates every so often.

My alternative solution is to use 4 variables to set the months and then run a current date check against each of these by pulling the month from the current date, and then changing that information back to a date and use the new date...

ex of the suboptimal code:

if Month(Date) > 10 Then
   varYear = Year(Date)
   strDate = "10/1/" & CStr(varYear)
   useDate = DateValue(strDate)

Which feels like I am going the long way around instead of just being able to pull a 90 day mod on a certain date when compared to the current date, as the excel spreadsheet formula does.

2

1 Answer 1

0

I guess(?) it could go like this:

DateAdd("q", DateDiff("q", DateSerial(2021, 1, 1), Date()), DateSerial(2021, 1, 1))

or:

DateAdd("q", 1 + DateDiff("q", DateSerial(2021, 1, 1), Date()), DateSerial(2021, 1, 1))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.