Results 1 to 8 of 8
  1. #1
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Guys

    I have a set of data on a form which I need to update or append a CSV file.
    I could do with a few tips on how to do this or even better any examples.
    Ideally a button on a form would be nice.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Hi Dave,

    Do you want to export all records behind the form, or specific data from the form?

    Access has a built-in method DoCmd.TransferText, but it works only with tables and queries.

  3. #3
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='789589' date='18-Aug-2009 18:02']Hi Dave,

    Do you want to export all records behind the form, or specific data from the form?

    Access has a built-in method DoCmd.TransferText, but it works only with tables and queries.[/quote]

    Hi Hans

    Ideally what the user see's on the form, but if it's easier to export all the table then the destination CSV can be over written every time.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    If you want to export the table or query behind the form, you can use code like this:

    Code:
    Private Sub cmdExport_Click()
      DoCmd.TransferText acExportDelim, , "tblData", "C:\Test\Data.csv", True
    End Sub
    substituting the correct names, of course.

    If you'd like to update or append just the current record, it becomes more complicated.

  5. #5
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts
    No this is fine Hans, does what it says on the tin.
    I may have to deal with some blank fields though, I'll deal with them when I've tested this.

    Thanks once again.

  6. #6
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts
    DoCmd.TransferText acExportDelim, , "tblData", "C:\Test\Data.csv", True

    Hi Hans

    This code creates the field data with quotes, ie

    "CAT","DOG","MOUSE"

    I need:

    CAT,DOG,MOUSE

    Instead, is there an alternative to the line of code?

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Hi Dave,

    You'll have to create an export specification and use that.
    - In Access, select the table.
    - Select File | Export...
    - In the wizard, specify the settings that you want.
    - In particular, set Text Qualifier to {none}
    - Instead of clicking Finish in the last step of the wizard, click Advanced...
    - You'll see the settings you've specified.
    - Click Save As...
    - Give the export specification a name (or accept the proposed one); write down the name for later.
    - Click OK until you're back in the wizard.
    - You don't have to finish the export, you can cancel it now.

    Now activate the Visual Basic Editor.
    Change the line

    DoCmd.TransferText acExportDelim, , "tblData", "C:\Test\Data.csv", True

    to

    DoCmd.TransferText acExportDelim, "NameOfExportSpecification", "tblData", "C:\Test\Data.csv", True

    where NameOfExportSpecification is the name you wrote down.
    The text file should now be created without quotes around the text values.

    WARNING: if any of the text values contains a comma, this will throw off the csv file because the comma will be seen as a field delimiter.

  8. #8
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Hans

    Got it working ok.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •