Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    MTSPEER is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    283

    Getting the right date format when exporting a file


    Hello,

    I want to get the name of a file like Example_08302017 1:40PM.xlsx for example.

    I tried the code:

    Format(Date, mmddyyyy hh:mm AM/PM) & .xlsx but it wouldn't work.

    Any suggestions? THanks

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    you need the quotes in the format:
    Format(Date, "mmddyyyy hh:mm AM/PM")

  3. #3
    MTSPEER is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    283
    it's not working. it is creating the file Example_08302017 12 and the file is blank

  4. #4
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    What does "not working" mean?? You say it IS creating the file? Please be more specific as to your question(s).

  5. #5
    MTSPEER is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    283
    idk what the file type is..It's not in excel format

  6. #6
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Please post your complete VBA code that is exporting the file.

  7. #7
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Is this right
    & .xlsx
    ?
    s'be
    & ".xlsx"

  8. #8
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Date() will always return 12:00 Am as the Time portion...for the Date and Time, which is what you apparently want, you'd need to use Now().

    Format(Now, "mmddyyyy hh:mm AM/PM")

    and with aytee111's contribution

    Format(Now, "mmddyyyy hh:mm AM/PM") & ".xlsx"

    although I suspect the spaces in the name will be problematical. Probably better to use

    Format(Now, "mmddyyyy_hh:mm_AM/PM") & ".xlsx"

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  9. #9
    MTSPEER is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    283
    I am still getting the same results. Here is my Code:

    Public Function ExportImportTemplate()
    Dim strFilePath As String
    strFilePath = "RESOURCE FOLDER\ASCEND\Import_Users_Report\ImportUsers_"
    strFilePath = strFilePath & Format(Now, "mmddyyyy_hh:mm_AM/PM") & ".xlsx"

    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "Import_Template", strFilePath, True

    MsgBox "The Import Users Report has been exported to the Import_Users_Report Folder!", vbOKOnly
    Here is the picture of the output file

    Click image for larger version. 

Name:	DateError.png 
Views:	14 
Size:	1.7 KB 
ID:	30161

  10. #10
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Take these issues one at a time.

    1. File name, add this line of code:
    Debug.Print Format(Now, "mmddyyyy_hh:mm_AM/PM")
    see what it is displaying

    2. No data in file:
    run the query, make sure it is producing data

    3. xlsx - there are known issues with exporting to xlsx. Change it to xls and use excel9 instead.

  11. #11
    MTSPEER is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    283
    1. It shows the correct time when I run Debug.Print

    I changed it to .xls and acSpreadsheetTypeExcel9 and got the same results

  12. #12
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Post your database - with one table (the results of your query), and this code.

  13. #13
    MTSPEER is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    283
    How do I attach a DB here?

  14. #14
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Click on Go Advanced, then the Attach icon

  15. #15
    MTSPEER is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    283
    DateFormat.accdb

    Here is the DB

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

Similar Threads

  1. Customize Date Report when exporting the data to excel format
    By fluffyvampirekitten in forum Access
    Replies: 1
    Last Post: 08-19-2015, 03:33 AM
  2. Exporting Query into excel with Todays Date in the file name
    By sam.eade in forum Import/Export Data
    Replies: 19
    Last Post: 01-28-2014, 04:37 PM
  3. Replies: 4
    Last Post: 03-12-2013, 06:49 PM
  4. Exporting to Excel Date Stamped File
    By BED in forum Import/Export Data
    Replies: 1
    Last Post: 08-07-2010, 05:53 PM
  5. Date format exporting to txt
    By timpepu in forum Access
    Replies: 1
    Last Post: 04-20-2010, 08:20 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