473,396 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how to export the result of a report to a fixed length file

5
In ACCESS 2007 I need the results of a report in a fixed format file format text file. The record length of the file is 80 characters. The first record is a header record. It has the format of

##SET14 space)today's date as a 8 digit date)a 6 character transaction count with leading zeros)

i.e.
##SET HRF10132009000013

The data records have a format of

X2(a 9 digit Id)(today's date as a 8 digit date)(5 digit number)(0100 concatenated to 2 digit year)

i.e.
X21234567901012200901359010110

I would appreciate some VBA code to do this.
Nov 5 '09 #1

✓ answered by ADezii

  1. Let's assume the Data Source for your Report is named tblTest and looks as such:
    Expand|Select|Wrap|Line Numbers
    1. Field1    Field2       Field3       Field4    Field5
    2. X2        123456790    11/4/2009    1359      09
    3. Y3        223456781    11/4/2009    899       09
    4. H7        222345699    11/4/2009    23456     09
  2. It's crude, but the following code will Output your Data in the approximate manner which you describe to C:\Output.txt:
    Expand|Select|Wrap|Line Numbers
    1. Dim MyDB As DAO.Database
    2. Dim rst As DAO.Recordset
    3.  
    4. Set MyDB = CurrentDb
    5. Set rst = MyDB.OpenRecordset("tblTest", dbOpenForwardOnly)
    6.  
    7. Open "C:\Output.txt" For Output As #1
    8.  
    9. With rst
    10.   Do While Not .EOF
    11.     Print #1, ![Field1] & ![Field2] & Format$(![Field3], "mmddyyyy") & _
    12.                Format$(![Field4], "00000") & ![Field5] & "0100"
    13.     .MoveNext
    14.   Loop
    15. End With
    16.  
    17. rst.Close
    18. Set rst = Nothing
    19.  
    20. Close #1
  3. Contents of Output.txt
    Expand|Select|Wrap|Line Numbers
    1. X21234567901104200901359090100
    2. Y32234567811104200900899090100
    3. H72223456991104200923456090100
  4. To be honest, your Post is a little confusing to me, but is this what you are after, or close to it?

8 2965
ChipR
1,287 Expert 1GB
You should find this tutorial helpful: Using The FileSystemObject With VB and VBA - Part 3
Nov 5 '09 #2
Megalog
378 Expert 256MB
Welcome to Bytes, jcgads..

First off, I suspect you're wanting more than just a way to generate a text file. You seem to be asking for ways to generate string values out of multiple sets of data first. Or maybe you're saying you already have a report that you want to export the contents of to a specifically named text file? The description you gave can be translated in a few different ways, so think about your wording a bit more.

You also have to break down what you are asking for into smaller steps, each of which need to be completely detailed. Remember, we dont know anything about your processes or objectives.

This is explained a bit better in the Posting Guidelines. If you still need assistance, then posting a set of better questions will give a much better response.
Nov 5 '09 #3
ADezii
8,834 Expert 8TB
  1. Let's assume the Data Source for your Report is named tblTest and looks as such:
    Expand|Select|Wrap|Line Numbers
    1. Field1    Field2       Field3       Field4    Field5
    2. X2        123456790    11/4/2009    1359      09
    3. Y3        223456781    11/4/2009    899       09
    4. H7        222345699    11/4/2009    23456     09
  2. It's crude, but the following code will Output your Data in the approximate manner which you describe to C:\Output.txt:
    Expand|Select|Wrap|Line Numbers
    1. Dim MyDB As DAO.Database
    2. Dim rst As DAO.Recordset
    3.  
    4. Set MyDB = CurrentDb
    5. Set rst = MyDB.OpenRecordset("tblTest", dbOpenForwardOnly)
    6.  
    7. Open "C:\Output.txt" For Output As #1
    8.  
    9. With rst
    10.   Do While Not .EOF
    11.     Print #1, ![Field1] & ![Field2] & Format$(![Field3], "mmddyyyy") & _
    12.                Format$(![Field4], "00000") & ![Field5] & "0100"
    13.     .MoveNext
    14.   Loop
    15. End With
    16.  
    17. rst.Close
    18. Set rst = Nothing
    19.  
    20. Close #1
  3. Contents of Output.txt
    Expand|Select|Wrap|Line Numbers
    1. X21234567901104200901359090100
    2. Y32234567811104200900899090100
    3. H72223456991104200923456090100
  4. To be honest, your Post is a little confusing to me, but is this what you are after, or close to it?
Nov 5 '09 #4
jcgads
5
Thanks, I will try it
Nov 6 '09 #5
jcgads
5
it works when I change the code so so that it outputs what I need.

My remaining problem i that I cannot figure out how to add a second and third selection criteria based on a fields which are not in the report but is in the query.
Nov 6 '09 #6
NeoPa
32,556 Expert Mod 16PB
As a general rule, when outputting data in record format, it is quite simple to design a query in exactly the right format (a single field laid out as required - fairly straightforward) then output this using :
Expand|Select|Wrap|Line Numbers
  1. DoCmd.TransferText
It really isn't necessary to re-invent the wheel.
Nov 8 '09 #7
jcgads
5
This does not answer the question of how to add multiple criteria to the print statement.
Nov 12 '09 #8
ADezii
8,834 Expert 8TB
@jcgads
Kindly post an example of the 'Multiple Criteria' that you are referring to.
Nov 12 '09 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: dps027 | last post by:
Hi all - I wonder if there is any way to specify in UDB for Windows version 7 so that in the DEL Export file, there is no double quote (i.e. ") nor any character strings surrounding the columns of...
4
by: Mandar | last post by:
I am trying to export crystal report to pdf. but i am getting folloing error: "Error in File C:\DOCUME~1\MKM-BA~1\ASPNET\LOCALS~1\Temp\temp_0c6b2c59-df8a-4b26-a570-a2189ee212ac.rpt: Access to report...
3
by: Daniel Wetzler | last post by:
Dear MSSQL- experts, I have a strange problem with SQLSERVER 2000. I tried to export a table of about 40000 lines into a text file using the Enterprise manager export assitant. I was astonished...
1
by: ellenh | last post by:
I have read postings on the similar subject including the posting from 2003 shown below. This process works fine to display a single page snapshot report in PowerPoint. I need to display...
7
by: glbdev | last post by:
I have aspnet code (C#) to create a Crystal Report and export to pdf (in browser) without a Crystal Report Viewer. Works great except when the user attempts to save the file from the browser. ...
2
by: arnabit | last post by:
Hi everyone, I am facing a problem in exporting CSV file.I able to export it properly in IE7 bbut in Mozila it seems the file name is changed and an extra , is added in the file name.say if the...
3
by: Wayne | last post by:
I'm trying to automate the export of a query to a text file using code. If I export the query manually I get the exact result that I want i.e. If I select the query then choose File/Export from...
2
hemantbasva
by: hemantbasva | last post by:
Note We need to have a template on server for generating report in multiple sheet as we do not had msoffice on server moreover this require a batch job to delete excel file created by the...
8
by: iheartvba | last post by:
Hi I am using Access 2007 and am trying to export a query to a fixed length text file. I tried using the following code to export the text file: DoCmd.TransferText acExportFixed, , "qryFFRDeFile",...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.