Results 1 to 10 of 10
  1. #1
    Rschadt is offline Novice
    Windows 11 Access 2016
    Join Date
    May 2025
    Posts
    5

    Export to Excel with dynamic field name from an access form

    Hello
    I want to grab a value that is selected on a form (it is a date) and have that be part of the file name when I export to excel.

    Something like this.... so the file name would be Dealer-Summary-11/30/2024.xlsx

    "F:\Finance & Accounting\Securitization\Rick-Securitization Data\Temp-Date\Dealer-Summary-" & [Forms]![Month-End-Form]!
    [List2] & ".xlsx"

  2. #2
    jojowhite's Avatar
    jojowhite is offline Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    334
    Code:
    Dim fName as string
    fName = "F:\Finance & Accounting\Securitization\Rick-Securitization Data\Temp-Date\Dealer-Summary-" & [Forms]![Month-End-Form]!
    [List2] & ".xlsx"
    
    DoCmd.TransferSpreadsheet acExport,acSpreadsheetTypeExcel12Xml,"YourTable/QueryName",fName,True

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,263
    Quote Originally Posted by Rschadt View Post
    Hello
    I want to grab a value that is selected on a form (it is a date) and have that be part of the file name when I export to excel.

    Something like this.... so the file name would be Dealer-Summary-11/30/2024.xlsx

    "F:\Finance & Accounting\Securitization\Rick-Securitization Data\Temp-Date\Dealer-Summary-" & [Forms]![Month-End-Form]!
    [List2] & ".xlsx"
    Windows will not accept / in a filename.!
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    Rschadt is offline Novice
    Windows 11 Office 365
    Join Date
    May 2025
    Posts
    5
    so I am guessing that i need to take the form date field and reformat it to like something near this?

    "F:\Finance & Accounting\Securitization\Rick-Securitization Data\Temp-Date\Dealer-Summary-" & Format[Forms]![Month-End-Form]!
    [List2],yyyy-mm-dd)"& ".xlsx" ?

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,263
    Code:
    Format[Forms]![Month-End-Form]!
    [List2],"yyyy-mm-dd") & ".xlsx" ?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    Rschadt is offline Novice
    Windows 11 Office 365
    Join Date
    May 2025
    Posts
    5
    I must be going blind, it looks right, but continue to get a not valid file name error. The form is using a query to provide a list of dates of valid data, I am wondering if that field is not recognized as a date within the macro? I use the field as a filter and it is working on the queries that are invoked with the selected date value.

    "F:\Finance & Accounting\Securitization\Rick-Securitization Data\Temp-Date\Dealer-Summary-" & Format[Forms]![Month-End-Form]!
    [List2], "yyyy-mm-dd") & ".xlsx"

  7. #7
    Rschadt is offline Novice
    Windows 11 Office 365
    Join Date
    May 2025
    Posts
    5
    I changed the folder location that didnt solve it either

    "C:\Users\Rick.Schadt\Downloads\Dealer-Summary-" & Format[Forms]![Month-End-Form]!
    [List2], "yyyy-mm-dd") & ".xlsx"

  8. #8
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,263
    Put it into a string variable and debug.print it.
    Do all the folders exist?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  9. #9
    Rschadt is offline Novice
    Windows 11 Office 365
    Join Date
    May 2025
    Posts
    5
    figured it out....needed an "=" at the start

    ="F:\Finance & Accounting\Securitization\Rick-Securitization Data\Temp-Date\Dealer-Summary-" & Format([Forms]![Month-End-Form]!
    [List2],"yyyy-mm-dd") & ".xlsx"

  10. #10
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,263
    Quote Originally Posted by Rschadt View Post
    figured it out....needed an "=" at the start

    ="F:\Finance & Accounting\Securitization\Rick-Securitization Data\Temp-Date\Dealer-Summary-" & Format([Forms]![Month-End-Form]!
    [List2],"yyyy-mm-dd") & ".xlsx"
    Depends on how you were using it. Just as a filename in a command, then No.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

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

Similar Threads

  1. Replies: 7
    Last Post: 11-27-2023, 02:27 PM
  2. Export Dynamic Recordset to Excel
    By pooldead in forum Access
    Replies: 4
    Last Post: 09-04-2019, 05:57 PM
  3. Replies: 10
    Last Post: 06-29-2015, 05:57 PM
  4. Replies: 2
    Last Post: 03-11-2015, 03:40 PM
  5. Dynamic Form, Dynamic labels/ captions?
    By JFo in forum Programming
    Replies: 15
    Last Post: 10-12-2011, 08:33 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