Page 2 of 2 FirstFirst 12
Results 16 to 23 of 23
  1. #16
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642

    One way is here:

    http://allenbrowne.com/subquery-01.html#AnotherRecord

    You can't use -1 because your data isn't really stored as a date. IOW, 1501 - 1 is 1500, not 1412.

    There are a number of us who do Access work, and not just moderators. You can start a new thread looking for candidates (a new thread will get more attention). I do some work on the side, but I have a full time job as well, so I only take on stuff I can fit into my schedule.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  2. #17
    Russellh is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    68
    I'll start that tab. THe Bill MOYR is a # that you can subtract from. We us 1509 for 2015 september . August will be 1508 so -1 works and should work even for regular dates as they use the format YYMMDD which can always be added to and subtracted from.

  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,642
    I don't see it that way. Subtract 1 from 0701; do you get 0612? It works during the year, but not across years. Even the YYMMDD doesn't work. Subtract 1 from 060601; you don't get 060531. If you want to do date comparisons/math, the field should be date/time. That said, the subquery in Allen's example should work, because it uses < rather than -1.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #19
    Russellh is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    68
    Agreed the way he did it with TOP but < should work. I just couldn't make it do it. And this is one of those where you cant find out 6 months from now something was inaccurate. So Im gonna get a pro to make it all work!! Thanks for all the help though!

  5. #20
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,641
    Is this the same issue in your other thread https://www.accessforums.net/access/...put-55353.html
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #21
    Russellh is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    68
    Yes as since it was a 2nd part question and pbaldy didnt respond for a while I assumed he closed it out and I created a new ticket to address the new problem.

  7. #22
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,641
    Well, you haven't addressed my last post in that thread.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #23
    InsuranceGuy is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Aug 2015
    Location
    Colorado
    Posts
    126
    You probably want to convert your dates to variant-date values before you start trying to manipulate them. This will allow you to use functions like DateAdd to compare sequential months.

    Here are series of functions I had stashed away for this purpose.

    Code:
    Option Compare Database
    
    
    'Functions included:
    'Y4MDToDate - Takes string input from YYYYMM or YYYYMMDD format and outputs a variant date
    'DateToY4MD - Takes variant date in and outputs YYYYMMDD format
    'DateToY4M  - Same as DateToY4MD but drops calendar day, outputs YYYYMM format
    'Y2MDToDate - Takes string input from YYMM or YYMMDD format and outputs a variant date
    'DateToY2MD - Takes variant date in and outputs YYMMDD format
    'DateToY2M  - Same as DateToY2MD but drops calendar day, outputs YYMM format
    
    
    
    
    Public Function Y4MDToDate(varDate As Variant) As Variant
    
    
        On Error GoTo errHandle
        
        If Len(varDate) = 8 Then
            'YYYYMMDD format
            Y4MDToDate = DateSerial(CInt(Left(varDate, 4)), CInt(Mid(varDate, 5, 2)), CInt(Right(varDate, 2)))
        ElseIf Len(varDate) = 6 Then
            'YYYYMM format
            Y4MDToDate = DateSerial(CInt(Left(varDate, 4)), CInt(Mid(varDate, 5, 2)), 1)
        Else
            'Incorrect format
            Y4MDToDate = Null
        End If
        
        Exit Function
    
    
    errHandle:
        Y4MDToDate = Null
    End Function
    
    
    Public Function DateToY4MD(varDate As Variant) As Variant
        
        On Error GoTo errHandle
    
    
        DateToY4MD = Format(varDate, "YYYYMMDD")
        Exit Function
    
    
    errHandle:
        DateToY4MD = Null
        
    End Function
    
    
    Public Function DateToY4M(varDate As Variant) As Variant
    
    
        On Error GoTo errHandle
        
        DateToY4M = Format(varDate, "YYYYMM")
        Exit Function
        
    errHandle:
        DateToY4M = Null
    
    
    End Function
    
    
    
    
    Public Function Y2MDToDate(varDate As Variant) As Variant
    
    
        On Error GoTo errHandle
        
        If Len(varDate) = 6 Then
            'YYMMDD format
            Y2MDToDate = DateSerial(CInt(Left(varDate, 2)), CInt(Mid(varDate, 3, 2)), CInt(Right(varDate, 2)))
        ElseIf Len(varDate) = 4 Then
            'YYMM format
            Y2MDToDate = DateSerial(CInt(Left(varDate, 2)), CInt(Mid(varDate, 3, 2)), 1)
        Else
            'Incorrect format
            Y2MDToDate = Null
        End If
        
        Exit Function
    
    
    errHandle:
        Y2MDToDate = Null
    End Function
    
    
    Public Function DateToY2MD(varDate As Variant) As Variant
        
        On Error GoTo errHandle
    
    
        DateToY2MD = Format(varDate, "YYMMDD")
        Exit Function
    
    
    errHandle:
        DateToY2MD = Null
        
    End Function
    
    
    Public Function DateToY2M(varDate As Variant) As Variant
    
    
        On Error GoTo errHandle
        
        DateToY2M = Format(varDate, "YYMM")
        Exit Function
        
    errHandle:
        DateToY2M = Null
    
    
    End Function
    Good luck,


    Jeff

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

Similar Threads

  1. Replies: 1
    Last Post: 08-02-2014, 02:41 PM
  2. Replies: 3
    Last Post: 03-11-2014, 07:32 PM
  3. Most recent Date query
    By SmartestIdiot in forum Queries
    Replies: 1
    Last Post: 01-11-2014, 07:56 AM
  4. Query Help Returning Most Recent Date's Value
    By cperry88 in forum Queries
    Replies: 1
    Last Post: 01-08-2014, 03:03 PM
  5. Replies: 8
    Last Post: 01-16-2013, 02:10 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