Results 1 to 3 of 3
  1. #1
    captiangvp is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2021
    Posts
    24

    VBA for button to format an export

    So, the project i'm working on is getting ready to be put in the hands of the end users and we are putting the finishing touches on things
    The users will not see the "file, home, create, etc" SO I have created a button to export the query as a csv file that has the date included on the file.


    My question is, How do i get it to export it using the formatting of "delimited by comma" and "including the field names on the first row" I'm not a perfect expert on access and i appreciate all the help tossed at me. I've searched the web and can't find an answer, or maybe i'm wording my search wrong. My code is shown below

    Code:
    Private Sub Export_Products_Click()
    Dim filename1 As String
    Dim theFilePath As String
    filename1 = "Products Export" & "_" & Format(Date, "dd-mm-yyyy") & ".csv"
    theFilePath = "C:\Users\Damian\Desktop\Work\Zimmerman"
     
    DoCmd.OutputTo acOutputQuery, "Products Export", acFormatTXT, filename1, False
    End Sub

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Explore DoCmd.TransferText command.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Also, it looks like you are NOT using the "theFilePath" in the DoCmd command, only "filename1".

    Here are options:
    Code:
    Private Sub Export_Products_Click()
        Dim filename1 As String
        Dim theFilePath As String
        
        filename1 = "Products Export" & "_" & Format(Date, "dd-mm-yyyy") & ".csv"
        theFilePath = "C:\Users\Damian\Desktop\Work\Zimmerman"
    
    
        DoCmd.OutputTo acOutputQuery, "Products Export", acFormatTXT, theFilePath & "\" & filename1, False
        
    End Sub
    Code:
    Private Sub Export_Products_Click()
        Dim filename1 As String
        Dim theFilePath As String
        
        filename1 = "Products Export" & "_" & Format(Date, "dd-mm-yyyy") & ".csv"
        theFilePath = "C:\Users\Damian\Desktop\Work\Zimmerman\"    '<<-- added backslash
    
    
        DoCmd.OutputTo acOutputQuery, "Products Export", acFormatTXT, theFilePath & filename1, False
        
    End Sub
    Code:
    Private Sub Export_Products_Click()
        Dim filename1 As String
        Dim theFilePath As String
        
        filename1 = "Products Export" & "_" & Format(Date, "dd-mm-yyyy") & ".csv"
        theFilePath = "C:\Users\Damian\Desktop\Work\Zimmerman\" & filename1     '<<-- added backslash and filename1
    
    
        DoCmd.OutputTo acOutputQuery, "Products Export", acFormatTXT, theFilePath, False
        
    End Sub

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

Similar Threads

  1. Replies: 0
    Last Post: 11-19-2014, 05:47 AM
  2. Replies: 4
    Last Post: 02-12-2014, 12:49 PM
  3. Export to Excel and format
    By aytee111 in forum Programming
    Replies: 7
    Last Post: 01-27-2014, 05:40 PM
  4. export format
    By kstyles in forum Reports
    Replies: 2
    Last Post: 07-07-2011, 07:01 PM
  5. Replies: 0
    Last Post: 03-24-2011, 11:09 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