Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 3rd, 2006, 07:58 AM
Registered User
 
Join Date: May 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to format txt file exported from access table

I am starter with access VBA and now have a problem when trying to export access table to txt file. I have an access table called tblCitationList, it has three column:ID,Volume, Issue and Pub date. It looks like:
-----------------------------------------
ID Volumn Issue Pub date
-----------------------------------------
1 113 15 2006
2 76 3 2004
-----------------------------------------

I want to export this table to txt file with the following format:

----------------------------------------------------
ID - 1
VI - 113 [from TblCitationlist "Volume"]
IP - 15 [from TblCitationlist "Issue"]
DP - 2006 [from TblCitationlist "Pub date"]

ID - 2
VI - 76 [from TblCitationlist "Volume"]
IP - 3 [from TblCitationlist "Issue"]
DP - 2004 [from TblCitationlist "Pub date"]
----------------------------------------------------

Could anyone help? Thanks very much!!

 
Old August 4th, 2006, 02:16 PM
pjm pjm is offline
Authorized User
 
Join Date: Jul 2006
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here's some simple code that should do the trick:

Dim db As Database
Dim rs As Recordset

Dim nRecords As Long, r As Long

    Set db = CurrentDb()
    Set rs = db.OpenRecordset(TableName, dbOpenDynaset)
    Open OutputFilename For Output As #1

    rs.MoveLast
    nRecords = rs.RecordCount
    rs.MoveFirst

    For r = 1 To nRecords

    Print #1, "ID - "; r
    Print #1, "VI - "; rs("Volume")
    Print #1, "IP - "; rs("Issue")
    Print #1, "DP - "; rs("Pub date")

        rs.MoveNext
    Next r

    rs.Close
    db.Close


-Phil-





Similar Threads
Thread Thread Starter Forum Replies Last Post
View txt File as DOS Format suresh.cgmohan VB How-To 2 September 27th, 2006 07:40 AM
Import a Comma separated txt file to SQL table arielote C# 2 April 17th, 2006 01:08 AM
Get table records into Txt or CSV format kapi.goel SQL Language 0 April 10th, 2006 01:47 AM
save file in csv, txt format in jsp URGENT ernidhi2003 JSP Basics 1 October 14th, 2004 04:59 PM
Export table to txt in Access XP midtowncreek Access 9 May 24th, 2004 08:02 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.