Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 139729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:29:14+00:00 2026-05-11T07:29:14+00:00

I am using a macro to export a table in a Microsoft Access database

  • 0

I am using a macro to export a table in a Microsoft Access database to a csv file in order to import into a mysql database. I ended up using a batchfile that would place a marker in the text file before the exporting took place, and then place everything after the last marker into a new file. This works fine, except for the fact that access does not append, but will recreate the file each time, so it is impossible to use any kind of marker.

Is there any way, using access or batch files or whatever, to either a) force access to append to a file, or to place a marker of its own, or b) export to a different file each time, possibly the filename being a variable such as the date, or c) overcome this behavior with outside manipulation

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T07:29:15+00:00Added an answer on May 11, 2026 at 7:29 am

    Instead of using a macro to export the table you could simply create some code to open the file, and append the data to it.

    How to use

    Simply copy the code to a VBA module in your application and call it like this:

    ' Export the Table 'Orders' to 'orders.csv', appending the data to the       ' ' existing file if there is one.                                             ' ExportQueryToCSV 'Orders', 'C:\orders.csv', AppendToFile:=True  ' Export the result of the query to 'stock.csv' using tabs as delimiters     ' ' and no header or quotes around strings                                     ' ExportQueryToCSV 'SELECT * FROM Stock WHERE PartID=2', _                  'C:\stock.csv', _                  AppendToFile:=False, _                  IncludeHeader:=False, _                  Delimiter:=chr(9), _                  QuoteString:=false 

    Code

    '----------------------------------------------------------------------------' ' Export the given query to the given CSV file.                              ' '                                                                            ' ' Options are:                                                               ' ' - AppendToFile : to append the record to the file if it exists instead of  '  '                  overwriting it (default is false)                         ' ' - Delimiter    : what separator to use (default is the coma)               ' ' - QuoteString  : Whether string and memo fields should be quoted           ' '                  (default yes)                                             ' ' - IncludeHeader: Whether a header with the field names should be the first ' '                  line (default no)                                         ' ' Some limitations and improvements:                                         ' ' - Memo containing line returns will break the CSV                          ' ' - better formatting for numbers, dates, etc                                ' '----------------------------------------------------------------------------' Public Sub ExportQueryToCSV(Query As String, _                             FilePath As String, _                             Optional AppendToFile As Boolean = False, _                             Optional Delimiter As String = ',', _                             Optional QuoteStrings As Boolean = True, _                             Optional IncludeHeader As Boolean = True)     Dim db As DAO.Database     Dim rs As DAO.RecordSet      Set db = CurrentDb     Set rs = db.OpenRecordset(Query, dbOpenSnapshot)     If Not (rs Is Nothing) Then         Dim intFile As Integer          ' Open the file, either as a new file or in append mode as required '         intFile = FreeFile()         If AppendToFile And (Len(Dir(FilePath, vbNormal)) > 0) Then             Open FilePath For Append As #intFile         Else             Open FilePath For Output As #intFile         End If          With rs             Dim fieldbound As Long, i As Long             Dim record As String             Dim field As DAO.field              fieldbound = .Fields.count - 1              ' Print the header if required '             If IncludeHeader Then                 Dim header As String                 For i = 0 To fieldbound                     header = header & .Fields(i).Name                     If i < fieldbound Then                         header = header & Delimiter                     End If                 Next i                 Print #intFile, header             End If              ' print each record'             Do While Not .EOF                 record = ''                 For i = 0 To fieldbound                     Set field = .Fields(i)                     If ((field.Type = dbText) Or (field.Type = dbMemo)) And QuoteStrings Then                         record = record & '''' & Nz(.Fields(i).value, '') & ''''                     Else                         record = record & Nz(.Fields(i).value)                     End If                     If i < fieldbound Then                         record = record & Delimiter                     End If                     Set field = Nothing                 Next i                 Print #intFile, record                 .MoveNext             Loop             .Close         End With         Set rs = Nothing         Close #intFile     End If     Set rs = Nothing     Set db = Nothing End Sub 

    Note that it’s not perfect and you may have to adapt the code to reflect how you want the data to be formatted, but the defaults should be fine in most cases.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 63k
  • Answers 63k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer I can think of 3 choices Modify stored procedure to… May 11, 2026 at 10:32 am
  • added an answer We are developing web parts using 3.5 SP1 and deploying… May 11, 2026 at 10:32 am
  • added an answer I am assuming that you have compiled your application to… May 11, 2026 at 10:32 am

Related Questions

I am using a rich text editor on a web page. .NET has feature
I am using a class library which represents some of its configuration in .xml.
I am using a perl script to POST to Google Appengine application. I post
I am using a cross page postback for Page A to pass data to
I am using a wxGenericDirCtrl, and I would like to know if there is
I am using a popup menu in Delphi. I want to use it in
I am using a codebehind page in ASP.NET to perform a SQL query. The
I am using a DataGridView control in a Windows Forms application. When a user
I am using a multi-dimensional dynamic array in delphi and am trying to figure
I am using a library that has headers without the .h This defeats visual

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.