Results 1 to 7 of 7
  1. #1
    jhlee2222 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2013
    Posts
    7

    Custom Text in a Query

    Is there any way to add custom text to the top of a query's output?
    I'm not talking about custom headers for each field in the query, but rather something like an overall heading that would appear as the top line or lines in a query, followed by the query results. I realize such a thing may sound like it would best be performed in a report, however, my goal is to output my query results as a CSV file. From what I've seen, exporting a report to CSV format just doesn't seem to work very well. My ideal output would look something like:

    CUSTOM TEXT STATEMENT HERE.
    SECOND CUSTOM TEXT STATEMENT HERE.
    Field1, Field2, Field3
    value1, value2, value3
    value4, value5, value6
    value7, value8, value9

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Maybe the DoCmd.TransferSpreadsheet Method. I don't do much of this sort of thing but I imagine you could have a template with named fields (ranges) or you could create a file each time using ranges.

    So, run it once to get your text. Then a second time to place your query results in the same file.
    http://msdn.microsoft.com/en-us/libr.../ff844793.aspx

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Are you trying to use export wizard?

    Maybe like (not tested):

    SELECT "This is statement 1" AS FieldA, Null AS FieldB, Null AS FieldC FROM tablename
    UNION SELECT "This is statement 2", Null, Null FROM tablename
    UNION SELECT "Field1", "Field2", "Field3" FROM tablename
    UNION SELECT Field1, Field2, Field3 FROM tablename;

    Whether or not the export will retain that order for the output is unknown. Also don't know if the field names FieldA, FieldB, FieldC can be excluded from the output.

    I think the range argument is for import from spreadsheet, not export to CSV.
    Last edited by June7; 01-14-2014 at 10:21 PM.
    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.

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I was looking at he TransferSpreadsheet and when you are exporting, there is not an option to choose ranges. It will always export to the first row. The ranges are only effective when Importing.

  5. #5
    jhlee2222 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2013
    Posts
    7
    June7, I was hoping something like what you described would work, and envisioned that as well. One major problem though is I really need the additional content on a line above the headings. And yes, I'm trying to use the Wizard, with it's very nice options for defining the type of delimiter, amongst other bells and whistles.

    ItsMe, thanks for looking into this for me as well. I see why it's so hard to suggest anything. I believe what I need is such an odd one-off.

    What I'm trying to do is make a template for data matching an import format for another program, and it requires special heading text to define the import file type, followed by column headers.

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    The export methods from a query object seem to consistantly output the header in the first row. Perhaps exporting a report to comma seperated text file and then using SHELL methods to copy and paste the entire text file, renaming as an .XLSX

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    The wizard has its limitations.

    The alternatives are:

    1. possibly the suggestion by ItsMe to clean up the CSV text file with SHELL scripting after export

    2. in VBA open a text file object and a recordset object and write one line at a time of data from the recordset to the text file
    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.

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

Similar Threads

  1. Custom Query Help
    By samanthaM in forum Access
    Replies: 8
    Last Post: 11-04-2012, 08:35 PM
  2. Custom Query field
    By yeleek in forum Queries
    Replies: 3
    Last Post: 06-07-2012, 07:58 AM
  3. Replies: 7
    Last Post: 04-16-2012, 03:31 PM
  4. Custom Date in Query
    By frdebelo in forum Queries
    Replies: 4
    Last Post: 09-22-2011, 07:01 AM
  5. Replies: 6
    Last Post: 07-18-2011, 12:56 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