Results 1 to 6 of 6
  1. #1
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,071

    Rolling Months within a Report

    I have a report in Access 2010 The Report is run monthly and has 5 Sections Each with a membership count by Line of business(there are 2) and a total. The query runs perfectly and the report is good with 1 Exception in the page header I have the Section headings with the column headings underneath 3 are unbound text boxes for the 3 previous months. for example running today would have Mar 2013, Apr 2013, and May 2013 as the section heading for those 3. I've put code in the detail section of the report so those 3 text boxes are populated with the correct information. However when I preview the report all 3 of those text boxes are blank. Anyone know the sequence is the page header populated prior to the detail format event? where else could I put this where it would work?

  2. #2
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,071
    Never mind I figured it out. Thanks

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Would you care to post the solution? I would be interested in your solution.

  4. #4
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,071
    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

  5. #5
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,071
    Oops confused myself the Code I posted was for a different report that gets the first of the month for each of the previous 12 months. The code I should have posted is in an Access Module


    Code:
    Public Function firstofmonth() as date
    
    firstofmonth = CDate(Month(Date()) & "/01/" & year(Date()))
    End Function

  6. #6
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,071
    sorry about that been a long day

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 12-02-2012, 02:10 AM
  2. Report Grouping - Months
    By Kirsti in forum Reports
    Replies: 2
    Last Post: 07-11-2012, 04:27 PM
  3. Replies: 9
    Last Post: 04-27-2011, 05:04 PM
  4. Replies: 2
    Last Post: 08-25-2010, 01:42 PM
  5. Total all months in query or report
    By Brian62 in forum Queries
    Replies: 2
    Last Post: 10-23-2009, 08:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums