Results 1 to 8 of 8
  1. #1
    kattatonic1 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Location
    Toronto, Canada
    Posts
    77

    Unhappy calc field producing unwanted spaces amidst the final string

    Hello,



    I am using a calculated field because the fiscal year of an important date will appear on many reports in the same format, and will be queried upon many times, etc.

    E.g. dates from April 1, 2013 to March 31, 2014 should produce "13/14"

    Here is my formula that works mighty fine:

    IIf(Month([dtmXDate])>3,
    Str(Year([dtmXDate])-2000) & "/" & Str(Year([dtmXDate])+1-2000),
    Str(Year([dtmXDate])-1-2000) & "/" & Str(Year([dtmXDate])-2000))

    EXCEPT it produces results like:
    b13/b14
    where the Bs are spaces

    instead of my desired:
    13/14

    Any help would be appreciated. I have not developed anything for a few years and am updating my skills and the version knowledge slowing but Shirley. :-)

    Regards, Kay

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Try this:

    Code:
    IIf(Month([dtmXDate])>3,
    Format([dtmXDate],"yy") & "/" & Format([dtmXDate],"yy")+1, 
    Format([dtmXDate],"yy")-1 & "/" & Format([dtmXDate],"yy"))


    or (uses the DateAdd() function)
    Code:
    IIf(Month([dtmXDate])>3,
    Format([dtmXDate],"yy") & "/" & Format(DateAdd("yyyy",1,[dtmXDate]),"yy"),
    Format(DateAdd("yyyy",-1,[dtmXDate]),"yy") & "/" & Format([dtmXDate],"yy"))

  3. #3
    kattatonic1 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Location
    Toronto, Canada
    Posts
    77
    Thanks, Steve, not a bad idea, but Format is not recognized in a calcalated field though.

    Does anyone else have any ideas?

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    use the TRIM function


    IIf(Month([dtmXDate])>3,
    Trim(Str(Year([dtmXDate])-2000)) & "/" & Trim(Str(Year([dtmXDate])+1-2000)),
    Trim(Str(Year([dtmXDate])-1-2000)) & "/" & Trim(Str(Year([dtmXDate])-2000)))

  5. #5
    kattatonic1 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Location
    Toronto, Canada
    Posts
    77
    rpeare, You're a star! That was so obvious, no wonder I missed it.

    Thanks! Works great.

    Kay

  6. #6
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    but Format is not recognized in a calcalated field though.
    Using a calculated field in a table is a bad ides.... I'm just saying.....

  7. #7
    kattatonic1 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Location
    Toronto, Canada
    Posts
    77
    Can I mark this as solved now, or does a moderator do that?

  8. #8
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You do.

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

Similar Threads

  1. Look Up table with string that contain spaces
    By Leonidsg in forum Database Design
    Replies: 1
    Last Post: 04-03-2013, 06:53 PM
  2. Update calc field after context Filter
    By bhammer in forum Forms
    Replies: 12
    Last Post: 11-05-2012, 02:16 PM
  3. calc field
    By nashr1928 in forum Forms
    Replies: 8
    Last Post: 11-09-2011, 09:21 PM
  4. Concat in SQL creates unwanted spaces
    By Deutz in forum Access
    Replies: 3
    Last Post: 12-07-2010, 11:43 PM
  5. Find Spaces in Field
    By stottle in forum Queries
    Replies: 6
    Last Post: 08-17-2009, 02:02 AM

Tags for this Thread

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