Results 1 to 11 of 11
  1. #1
    templeowls is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    305

    Can a form alter the composition of a date format?


    I'm looking for my form to separate date components by a period or a dash, rather than a slash. For instance, 26-5-2021 or 26.5.2021 rather than 26/5/2021

    Any idea?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    did you try: format([dateFld],"dd-mm-yyyy")

  3. #3
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Probably several ways to accomplish, depending on whether or not you intend to just view, modify the value or store it in a table field. IMO that has to be revealed because f'rinstance, no point in giving you an expression for a calculated field that needs to be bound because you can't bind them to table fields.
    EDIT - Perhaps I focused too much on the record itself. Format function will show as you wish but won't store it that way. However, it will also change the value to a string so beware of that. It is also possible that the last Monday in a year can be reported as the wrong week should week calculations come in to play.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    templeowls is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    305
    To ranman: In a query or the form itself? I'm not sure where to put that in the form properties

  5. #5
    templeowls is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    305
    To micron: So the reason I'm looking to remove the slashes is that I have a VBA that exports the entry to a pdf and I want to use the date as a component in the file name. However, windows doesn't allow slashes in file names (periods or dashes are fine tho). So I think I just need to modify the value in the form itself but I could be wrong and hence why I'm here lol

  6. #6
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    Just format the date with the dashes in your export routine.
    No need to mess with the format in the form at all.

    Code:
    Dim sFilename  as String
    
    sFilename = "MyExport_" & format (Me.txtYourDateFieldControl, "yyyy-mm-dd") & ".pdf"
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  7. #7
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    I see. I often use dates for file versions but just use numbers: 05262021 is today (US date format).
    If you have code that's building a file path string, use Replace function on it and replace / with - or . Then output as a file.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    templeowls is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    305
    That worked Minty! Thank you! You guys are seriously the best

  9. #9
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    I use that specific format (YYYYMMDD) almost all the time, as the files created with the same starting name will then sort by date correctly, if you sort the folder contents by name.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  10. #10
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    I'm lazy so I like mine better
    sFilename = "MyExport_" & format (Me.txtYourDateFieldControl, "yyyy-mm-dd") & ".pdf"
    sFilename = "MyExport_" & Replace(Me.txtYourDateFieldControl, "/","-") & ".pdf"
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  11. #11
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    Quote Originally Posted by Micron View Post
    I'm lazy so I like mine better
    sFilename = "MyExport_" & format (Me.txtYourDateFieldControl, "yyyy-mm-dd") & ".pdf"
    sFilename = "MyExport_" & Replace(Me.txtYourDateFieldControl, "/","-") & ".pdf"
    I do have to agree it's significantly less typing
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

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

Similar Threads

  1. Replies: 3
    Last Post: 12-30-2016, 10:27 AM
  2. Replies: 4
    Last Post: 03-12-2013, 06:49 PM
  3. ALTER TABLE does not set field "format"
    By GraeagleBill in forum Programming
    Replies: 5
    Last Post: 09-07-2012, 01:11 PM
  4. Date format on Form
    By onenessboy in forum Forms
    Replies: 4
    Last Post: 12-07-2010, 06:28 AM
  5. Automated Letter Composition
    By jmwheatley in forum Programming
    Replies: 7
    Last Post: 09-20-2009, 05:20 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