Results 1 to 11 of 11
  1. #1
    Mpike926's Avatar
    Mpike926 is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    May 2012
    Location
    Florida
    Posts
    43

    Auto Count Month in Continuous Form

    Hi all, thanks for reading. Ill do my best to explain.
    We use our database to manage assets, one of which is I have a cashflow that shows all income and all expenses as columns across the top.
    One of the columns is month number, which numbers (up to 60) the rows, for payments to be entered.
    These are just numbers however, and I was looking for a way to get the name of the month to actually show instead of the number. The field is called MonthNumber, and I used the formula =MonthName(MonthNumber]) in an unbound cell, which does correctly change the number to the name of the month. However when it gets to 13, the unbound field yeilds an error, obviously because there is no 13th month. How do i fix this for records 13-60?


    Thanks for the help.

  2. #2
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    You will have to tell Access that 13, 25, 37 . . . etc are all January; 14, 26, 38 . . . are February . . .
    A Case statement might be good for this.
    Or you can create a formula that if the number is > 12 . . . then divide by 12 and get the remainder . . . till the remainder is less than 13 - and then use THAT number to determine the month.
    I hope this helps!

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Go to an existing standard Module, or if need be, create one, and enter this code

    Code:
    Function ReturnMonthName(MNumber As Integer) As String
     
    Select Case MNumber
    
     Case 1 To 12
      ReturnMonthName = MonthName(MNumber)
    
     Case Else
      ReturnMonthName = MonthName(MNumber Mod 12)
    
    End Select
     
    End Function
    Then in the Control Source for your Unbound Textbox, use this

    =ReturnMonthName([MonthNumber])

    When you Save the Module, be sure to not name it ReturnMonthName! When a Module and a Function within the Module have the same name it confuses the Access Gnomes no end!

    Linq ;0)>

  4. #4
    Mpike926's Avatar
    Mpike926 is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    May 2012
    Location
    Florida
    Posts
    43
    Linq, the code worked great with one exception, the Month of December populated the first time, but when it comes back around to record #24, 36,48 and 60, it yields an error. THought this was strange

  5. #5
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    MOD returns 0 when the number is 24, 36, 48 & 60 . . . and there isn't a month associated with 0.
    You could add another Case to the Case statement:
    Case 24, 36, 48, 60
    MonthName(12)

  6. #6
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Sorry, for not getting back to you more quickly, I was away from my box most of the day! Robeen's exactly right, of course! I Didn't test it out far enough! My bad!

    Replace what I gave you with
    Code:
    Function ReturnMonthName(MNumber As Integer) As String
    
    Select Case MNumber
     
     Case 12, 24, 36, 48, 60
      ReturnMonthName = "December"
     
     Case Else
      ReturnMonthName = MonthName(MNumber Mod 12)
    
    End Select
     
    End Function
    Linq ;0)>

  7. #7
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    How about this?

    Code:
    Function ReturnMonthName(MNumber As Integer) As String
    
       ReturnMonthName = MonthName((MNumber Mod 12) + Abs((MNumber Mod 12) = 0) * 12)
    
    End Function
    Could also be used in an unbound text box:
    Code:
    = MonthName((MonthNumber Mod 12) + Abs((MonthNumber Mod 12) = 0) * 12)
    Last edited by ssanfu; 05-12-2012 at 02:20 AM. Reason: added formula

  8. #8
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Very clever hack!

    Linq ;0)>

  9. #9
    Mpike926's Avatar
    Mpike926 is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    May 2012
    Location
    Florida
    Posts
    43
    Man, you guys (or gals) are great. I just started using access, well using it with code, Ive always just done simple things in querys and what have you, but this is really my first intro to code.
    Linq, the second versionw works wonders... sanfu, I tried yours which works as well, however, I need the month name to be controlled so I can bring the names over with me onto reports. Something I find terribly difficult to do if it is a calculated field.

  10. #10
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Glad we could help!

    Good luck with your project!

    Linq ;0)>

  11. #11
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    ... sanfu, I tried yours which works as well, however, I need the month name to be controlled so I can bring the names over with me onto reports. Something I find terribly difficult to do if it is a calculated field.
    Don't quite understand what you mean. The results are the same....

    But as long as you have something you understand and can use, all's good!

    Echoing Missinglinq :

    Glad we could help!
    Good luck with your project!

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

Similar Threads

  1. Replies: 14
    Last Post: 02-23-2012, 06:32 PM
  2. creating a report to count by month
    By kwooten in forum Reports
    Replies: 13
    Last Post: 09-12-2011, 01:29 PM
  3. how to get auto numbering on continuous form records
    By shubhamgandhi in forum Programming
    Replies: 1
    Last Post: 08-04-2011, 02:26 PM
  4. Replies: 11
    Last Post: 12-09-2010, 10:55 PM
  5. Individual weekday count in a month
    By Silver_A in forum Queries
    Replies: 6
    Last Post: 04-16-2010, 08:14 PM

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