Results 1 to 9 of 9
  1. #1
    RJC is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Location
    Fairfax, VA
    Posts
    5

    Calculated Field Formatting


    I have a database table with 4 fields. One is calculated from the others - one of which is a date/time field. The calculation works but I can't get the date portion in the format that I want (yyyymmdd) even though the date field is itself formatted this way. See attachments. How do I get the resultant calculated field format to look like this: 000a:wzyx:20130730. The first part works fine but the date portion always comes out mm/dd/yy - so, it looks like this: 000a:wzyx:07/30/2013. Any ideas?
    Attached Thumbnails Attached Thumbnails 1.PNG   2.PNG  

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    I haven't used calculated fields, but can your expression use the Format() function?

    A & B & Format(Date, "yyyymmdd")
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

    Unhappy

    Before heading down the path of calculated fields, you might want to read this:
    http://allenbrowne.com/casu-14.html

    Be sure to read the last 3 paragraphs.... multiple times.

  4. #4
    RJC is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Location
    Fairfax, VA
    Posts
    5

    Calculated Field Formatting

    Quote Originally Posted by ssanfu View Post
    Before heading down the path of calculated fields, you might want to read this:
    http://allenbrowne.com/casu-14.html

    Be sure to read the last 3 paragraphs.... multiple times.

    Good point; thanks. So I put the calculated field in a query instead of the table. The formatting problem remains the same. And, the Format (Date, "yyyymmdd") suggestion doesn't work either. In the resultant calculated field the date portion always comes out mm/dd/yy.

  5. #5
    RJC is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Location
    Fairfax, VA
    Posts
    5
    Good point; thanks. So I put the calculated field in a query instead of the table. The formatting problem remains the same. And, the Format (Date, "yyyymmdd") suggestion doesn't work either. In the resultant calculated field the date portion always comes out mm/dd/yy.

  6. #6
    ketbdnetbp is offline Competent Performer
    Windows 7 32bit Access 2003
    Join Date
    Mar 2011
    Location
    Midwest
    Posts
    254
    RJC -

    I might try...

    1. Go to the table in design view under ItemDate, where you have yyyymmdd in the format row, change yyyymmdd to Short Date.
    2. Go to query, delete ItemDate column then add ItemDate back into the query.
    3. Add calculated column to query, like:

    xUnique: [Lot #] & ":" & [ItemType] & ":" & DatePart("yyyy",[ItemDate]) & IIf(Len(Month([ItemDate]))=1,"0" & Month([ItemDate]),Month([ItemDate])) & IIf(Len(Day([ItemDate]))=1,"0" & Day([ItemDate]),Day([ItemDate]))

    Hope this helps,

    Jim
    Last edited by ketbdnetbp; 08-16-2013 at 10:34 AM. Reason: forgot to add hashtag in [Lot]

  7. #7
    RJC is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Location
    Fairfax, VA
    Posts
    5
    Perfect Jim! This works. Thanks for the help.

  8. #8
    ketbdnetbp is offline Competent Performer
    Windows 7 32bit Access 2003
    Join Date
    Mar 2011
    Location
    Midwest
    Posts
    254
    RJC -

    Happy to help. Also, that code assumes that there will never be a null value in each of the fields used in the calculation. If there are null values in any of those fields, the calculation will not work properly. Are nulls a possibility? Please advise.

    Lastly, most experts recommend not using special characters in field names; just a heads-up.

    All the best,

    Jim

  9. #9
    RJC is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Location
    Fairfax, VA
    Posts
    5
    Jim,

    Thanks for the heads-up; I'll change the field name accordingly. As for null values, there should never be any in the finished product. Since the database is still in development there currently are a few and they don't seem to effect the calculation (except, of course, some pieces are just missing). I haven't restricted the table to prevent nulls yet but I will. Thanks again for the help.

    RJC

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

Similar Threads

  1. Replies: 1
    Last Post: 04-21-2013, 03:20 PM
  2. Replies: 3
    Last Post: 02-13-2013, 10:15 AM
  3. Replies: 3
    Last Post: 11-20-2012, 11:14 PM
  4. Replies: 5
    Last Post: 12-10-2011, 11:49 AM
  5. Formatting a Calculated Field
    By e_lady333 in forum Queries
    Replies: 0
    Last Post: 03-17-2010, 06:11 PM

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