+ Reply to Thread
Results 1 to 4 of 4

Thread: Dynamic change of cell info based on user input?

  1. #1
    Barn Regular CCCSteve is on a distinguished road CCCSteve's Avatar
    Join Date
    Feb 2010
    Posts
    63
    Rep Power
    2

    Dynamic change of cell info based on user input?

    Hello again all,

    I am looking to generate a report that will allow a user to select a month which will auto generate each month afterwards into the next text box. The reason for this is because the report needs to be from that month forward with projected data.


    Example: User selects May from a drop down.

    Cell 1 = May
    Cell 2 = June
    ........[And so on]................
    Cell 9 = January
    Cell 10 = February
    Cell 11 = March
    Cell 12 = April [ End of cells in row since May was the start point ]



    So if I have a dropdown in my report already does anybody know how I could dynamically populate the data once the user selects the month?



    Thanks for any help

  2. #2
    I like Data Cubes too... Lauramc has a spectacular aura about Lauramc has a spectacular aura about Lauramc's Avatar
    Join Date
    Mar 2008
    Location
    Far Far Away
    Posts
    387
    Real Name
    Laura
    Rep Power
    5

    I suppose you could use a stored procedure for this. Converting each month to a datetime would be the best way for the iteration. Here is a sample of what that might look like:
    Code:
    -- This would be your parameter:
    DECLARE @StartMonth int
    SET @StartMonth = 5 -- Just for testing: this is the month the user selects
    
    -- This is just to convert the month to a date.
    DECLARE @StartDate datetime
    SET @StartDate = CAST(CAST(@StartMonth as varchar(2)) + '/01/' + CAST(YEAR(GETDATE()) as varchar(4)) as datetime)
    
    DECLARE @EndDate datetime
    SET @EndDate = DATEADD(year, 1, @StartDate)
    
    -- Now create a table to store the list of months in
    DECLARE @MonthTab TABLE
    (
        [month_num] int,
        [month_name] varchar(20)
    )
    
    -- Create a counter variable
    DECLARE @d Datetime
    SET @d = @startdate
    
    -- Now loop through the list to get your months.
    WHILE @d < @EndDate
    BEGIN
        INSERT INTO @MonthTab VALUES( MONTH(@d), DATENAME(month, @d) )
        SET @d = DATEADD(month, 1, @d)
    END
    
    -- Finally get the list of months from you table.  Now this can be inserted on your report.    
    SELECT * FROM @MonthTab
    
    I know this seems lengthy, but there is no way to do this without some sort of iteration.
    "The Enrichment Center is required to remind you that first you will be baked, then there will be cake." - GLaDOS

  3. #3
    Barn Regular CCCSteve is on a distinguished road CCCSteve's Avatar
    Join Date
    Feb 2010
    Posts
    63
    Rep Power
    2

    Wow

    That is one well thought out reply. I will give it a try and see if I can get it working. Thanks a lot!

  4. #4
    I like Data Cubes too... Lauramc has a spectacular aura about Lauramc has a spectacular aura about Lauramc's Avatar
    Join Date
    Mar 2008
    Location
    Far Far Away
    Posts
    387
    Real Name
    Laura
    Rep Power
    5

    You can cut and paste that into your query window. Just change the bit with the parameters so it's a stored procedure accepting a month as an input.

    Then in your report create a value list with numbers for month values and names for the labels.

    Let me know if you need help with any of that.

    The sample I posted is ready to test as is. So feel free to try it in your query window.
    "The Enrichment Center is required to remind you that first you will be baked, then there will be cake." - GLaDOS

+ Reply to Thread

Similar Threads

  1. table cell problem
    By todd2006 in forum HTML & CSS Help
    Replies: 9
    Last Post: September 4th, 2009, 02:06 PM
  2. Adding text after user input..?
    By Centurion in forum JavaScript Programming
    Replies: 2
    Last Post: May 18th, 2009, 12:39 PM
  3. Replies: 10
    Last Post: December 5th, 2008, 07:11 AM
  4. Change TextBox input language
    By dragon rider in forum JavaScript Programming
    Replies: 14
    Last Post: October 13th, 2008, 01:31 AM
  5. Dynamically Reference Worksheet Cell/Range
    By BLaaaaaaaaaarche in forum Microsoft Office
    Replies: 2
    Last Post: June 18th, 2008, 04:59 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO