I have a field in the query for the date of eligibility which is the first of each month. I was trying to use that field to set the headings but the order of operations in Access the textbox was populated before I could use the field. I then realized that the dates were constant. It would always be the previous 3 months so June would be March April and May, July would be april, May and June. Simply set the text boxes = DateAdd("m",-3,firstofmonth()) changing the -3 to -2 and -1.
FirstofMonth is a SQL Server function that returns the first of a given month based on the parameter @d1
firstofmonth(0) gives the first of the current month (1) previous month (2) month before that etc.
Code:
CREATE FUNCTION [dbo].[firstofmonth]
(
-- Add the parameters for the function here
@d1 numeric
)
RETURNS Date
AS
BEGIN
-- Declare the return variable here
DECLARE @firstofmonth date
DEclare @m1 date
Declare @d2 as numeric
If (@d1 >= 0)
set @d2=@d1*-1
set @m1 = DateAdd(m,@d2,getdate())
-- Add the T-SQL statements to compute the return value here
set @firstofmonth = Cast(str(Month(@m1)) + '/01/' + str(year(@m1)) as date)
-- Return the result of the function
RETURN @firstofmonth;
END