Results 1 to 12 of 12
  1. #1
    mrnikeswsh is offline Novice
    Windows 7 Access 2002
    Join Date
    Jan 2010
    Posts
    7

    Exporting Help

    I have done many access exports over the years, but they have all been csv or fixed with, with nothing too fancy.

    I was wondering if access can export a special character between records or possibly a carriage return.

    For example, I do not want this
    1
    2
    3

    I would like it to export
    1
    #
    2
    #
    3
    #


    or even
    record 1x
    x
    record 2x
    x


    record 3x
    x

    If someone knows if this is possible or can guide me in the right direction that would be great.

    Thanks again,
    Brian

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You can write your own export routine using Print # statements.

  3. #3
    mrnikeswsh is offline Novice
    Windows 7 Access 2002
    Join Date
    Jan 2010
    Posts
    7

    print #?

    Where exactly would I use that? Is it within VB or access itself I never heard of that.

    I have a "query" that looks up my data, and I normally just "right click" and export. and setup my specs.

    hate to be a pain, but can you give me a bit more detail

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    In VBA Help (not Access Help) look up Open #, Write # and Print #. I will help you write the routine if you want but you need to know what those functions do first.

  5. #5
    mrnikeswsh is offline Novice
    Windows 7 Access 2002
    Join Date
    Jan 2010
    Posts
    7

    so close...yet I am so far away

    ok, for not have much knowledge on vb, I was able to find some code in different places and make a small script. It works, but I only get the 1st record in my dataset. The code I found was for delimiting fields. So I know exactly where my problem is, I just don't know the syntax to make it work for each record and not each field. This script only exports my first record.

    Any help would be great. thanks

    Option Compare Database

    Private Sub cmdExportDB_Click()

    Dim rst As DAO.Recordset
    Dim db As DAO.Database
    Dim fld As DAO.Field
    Dim strText As String
    Dim track1 As String
    Dim track2 As String
    Dim track3 As String
    Dim badge As String



    Set db = CurrentDb


    track1 = Chr(1)
    track2 = Chr(2)
    track3 = Chr(3)

    Set rst = db.OpenRecordset("select * from export")

    Open "c:\badges\here.txt" For Output As #1


    Do While Not rst.EOF
    For Each fld In rst.Fields
    badge = track1 & vbNewLine & track2 & fld.Value
    strText = badge & vbNewLine & track3 & vbNewLine & vbNewLine

    Next

    rst.MoveNext

    Loop
    Print #1, strText
    Close #1

    End Sub

  6. #6
    Bjorn is offline Novice
    Windows XP Access 2003
    Join Date
    Jan 2010
    Posts
    7
    Hi,
    look at my solution to another problem (see link below). Maybe this helps you (depending on your purpose of exporting data). Your result will easily show up in Excel. Either that is your final destination and you are satisfied, or you can use export functionalities in Excel to create any txt-like table.

    https://www.accessforums.net/import-...port-3439.html

  7. #7
    mrnikeswsh is offline Novice
    Windows 7 Access 2002
    Join Date
    Jan 2010
    Posts
    7
    Sorry, but I don't see how the two are related. Thanks for you reply though.. This is just creating a txt file with special formating and characters that are not present in the actual table. Such as Chr (1) (2) and (3) With vbnewline and such.

    The problem is this section
    ~~~~
    Do While Not rst.EOF
    For Each fld In rst.Fields
    badge = track1 & vbNewLine & track2 & fld.Value
    strText = badge & vbNewLine & track3 & vbNewLine & vbNewLine
    ~~~~~

    The problem is the "for each fld in rst.fields" Since I only have 1 field in this table, with many records, I get the 1 record exported but then no others.

    The export would look like this
    chr (1)
    chr (2) record 1
    chr (3)
    blank line
    then repeat... I just don't get it to repeat for the next records. The chr (1) are binary characters I think (smiley face) which I need in my file.

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Try outputting the record *before* you move to the next input record.
    Code:
    Private Sub cmdExportDB_Click()
        Dim rst As DAO.Recordset
        Dim db As DAO.Database
        Dim fld As DAO.Field
        Dim strText As String
        Dim track1 As String
        Dim track2 As String
        Dim track3 As String
        Dim badge As String
        Set db = CurrentDb
        track1 = Chr(1)
        track2 = Chr(2)
        track3 = Chr(3)
        Set rst = db.OpenRecordset("select * from export")
        Open "c:\badges\here.txt" For Output As #1
        Do While Not rst.EOF
            For Each fld In rst.Fields
                badge = track1 & vbNewLine & track2 & fld.Value
                strText = badge & vbNewLine & track3 & vbNewLine & vbNewLine
            Next
            Print #1, strText
            rst.MoveNext
        Loop
        Close #1
        rst.Close
        Set rst = Nothing
    End Sub

  9. #9
    mrnikeswsh is offline Novice
    Windows 7 Access 2002
    Join Date
    Jan 2010
    Posts
    7
    YOU DA MAN!

    I think that did it, thank you so much!

  10. #10
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Did you notice how much easier the code is to read when you use the code tags (which is the "#" on the toolbar)? Glad we could help. Are you ready to follow the link in my sig and mark this thread as Solved?

  11. #11
    mrnikeswsh is offline Novice
    Windows 7 Access 2002
    Join Date
    Jan 2010
    Posts
    7
    not sure what you mean by easier to read with the #....but yes, I will mark this received.

    Thank you again!

    Brian

  12. #12
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    If you post by going advanced instead of the quick post you will see a tool bar that has a "#" symbol on it. That is to insert code tags into your post.

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

Similar Threads

  1. Really Need Help With Exporting to Excel
    By graviz in forum Import/Export Data
    Replies: 0
    Last Post: 09-24-2009, 08:29 AM
  2. Help with exporting data
    By wee in forum Import/Export Data
    Replies: 10
    Last Post: 09-24-2009, 01:15 AM
  3. Exporting Quieres - Filenames
    By jquickuk in forum Programming
    Replies: 1
    Last Post: 05-02-2009, 06:51 PM
  4. Exporting a Switchboard
    By Hawkx1 in forum Forms
    Replies: 1
    Last Post: 07-08-2008, 06:59 AM
  5. Exporting pivot table
    By nesbtech in forum Import/Export Data
    Replies: 1
    Last Post: 04-28-2008, 12:19 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