Criteria last tuesday of the next month (1 Viewer)

robina

Access Developer
Local time
Yesterday, 16:48
Joined
Feb 28, 2012
Messages
102
I have read through all the date threads I could find but didn't see a solution. I need my query criteria to be >the last tues of next month. How would I write this?

Thank you.
 

plog

Banishment Pending
Local time
Yesterday, 18:48
Joined
May 11, 2011
Messages
11,696
I would make it a function using this code:

Code:
Function getNextMonthLastTuesday() As Date
    ' returns date of last tuesday of next month
Dim ret As Date
ret = DateSerial(Year(Date), Month(Date) + 2, 0)
    ' gets date of last day of next month

daystosubtract = Weekday(ret)
If (daystosubtract >= 3) Then daystosubtract = daystosubtract - 3 Else daystosubtract = daystosubtract + 4
    'determines how many days prior to ret that Tuesday occured, will be subtracted from ret
    
getNextMonthLastTuesday = DateAdd("d", -1 * daystosubtract, ret)

End Function

Then use getNextMonthLastTuesday() to return the value wherever you need to use it.
 

robina

Access Developer
Local time
Yesterday, 16:48
Joined
Feb 28, 2012
Messages
102
I get the "Undefiend function in expression error when the query runs.
 

bob fitz

AWF VIP
Local time
Today, 00:48
Joined
May 23, 2011
Messages
4,731
Where have you put the functions code. It needs to be in a general module, not in a forms module.
 

robina

Access Developer
Local time
Yesterday, 16:48
Joined
Feb 28, 2012
Messages
102
I put it in a general module. I've attached a screen shot. thank you.
 

Attachments

  • module.jpg
    module.jpg
    80.8 KB · Views: 122
Last edited:

robina

Access Developer
Local time
Yesterday, 16:48
Joined
Feb 28, 2012
Messages
102
I figured it out. The module name cannot be the same as the function name. It works now. thank you.
 

Users who are viewing this thread

Top Bottom