Page 2 of 2 FirstFirst 12
Results 16 to 18 of 18
  1. #16
    RunTime91 is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Dec 2014
    Posts
    284
    I changed the IIf to a CASE



    The below seems to work effectively (and efficiently)

    But I remain convinced there is a better way - I just can't seem to find it.
    Code:
    Dim Period As String
    
    
    Select Case Me.CmboSumResults
    
    
      Case "January"
        [Period] = "December"
        Case "February"
          [Period] = "January"
          Case "March"
            [Period] = "February"
            Case "April"
              [Period] = "March"
              Case "May"
                [Period] = "April"
                Case "June"
                  [Period] = "May"
                Case "July"
                  [Period] = "June"
              Case "August"
                [Period] = "July"
            Case "September"
              [Period] = "August"
          Case "October"
            [Period] = "September"
        Case "November"
          [Period] = "October"
      Case "December"
        [Period] = "November"
      
    End Select

  2. #17
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,742
    But I remain convinced there is a better way - I just can't seem to find it.
    Well, code is code. Here's another way. Pass it your string month name from the combobox.

    Code:
    Public Function fcnGitmo(Mo As String) As String
        Dim nMo As Integer
        Dim sWork  As String
        Dim sList As String
        sList = "JanFebMarAprMayJunJulAugSepOctNovDec"
        sWork = Left(Mo, 3)
        nMo = InStr(sList, sWork)
        nMo = nMo \ 3 + 1
        nMo = IIf(nMo = 1, 12, nMo - 1)
        fcnGitmo = MonthName(nMo)
    End Function

  3. #18
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Sorry for the delay, yesterday was busy and today I feel blah. This is where I was headed in post 14, the 2 ending variables could be used in your SQL:

    Code:
      Dim strMonth As String
      Dim intYear As Integer
      Dim strPrevMonth As String
      Dim intPrevYear As Integer
      Dim dteDate As Date
      Dim dtePrevDate As Date
    
      strMonth = Me.CmboSumResults.Column(0)
      intYear = Me.CmboSumResults.Column(1)
      dteDate = CDate(strMonth & "/1/" & intYear)
    
      dtePrevDate = DateAdd("m", -1, dteDate)
    
      strPrevMonth = Format(dtePrevDate, "mmmm")
      intPrevYear = Year(dtePrevDate)
      MsgBox strPrevMonth & " " & intPrevYear
    davegri's method I'm sure works, but you'd also need to calculate year, though it would only be different when looking at January.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 02-24-2020, 05:53 PM
  2. Replies: 2
    Last Post: 03-16-2018, 09:44 AM
  3. Populating a Textbox
    By Daisy509th in forum Access
    Replies: 1
    Last Post: 03-16-2018, 07:12 AM
  4. Replies: 3
    Last Post: 05-16-2013, 08:21 PM
  5. Replies: 12
    Last Post: 01-18-2012, 10:02 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