473,405 Members | 2,261 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,405 software developers and data experts.

Split fields into lines

171 100+
Hi all

I have a query with two fields. When i use the export to text i want the fields
to show as two lines in the text file. but now it is showing as same line. Pls help

eg: my result is now as xxxx yyyyyyy
i need to get the result as
xxxx
yyyyyyy

Hope my question is clear. Pls help me
Thank you all
May 26 '08 #1
12 2492
ADezii
8,834 Expert 8TB
Hi all

I have a query with two fields. When i use the export to text i want the fields
to show as two lines in the text file. but now it is showing as same line. Pls help

eg: my result is now as xxxx yyyyyyy
i need to get the result as
xxxx
yyyyyyy

Hope my question is clear. Pls help me
Thank you all
  1. Remove the 2 Fields from the Query and replace them with a single Calculated Field named Split_Field (or anything else for that matter) as in:
    Expand|Select|Wrap|Line Numbers
    1. Split_Field: [Field1] & Chr$(13) & Chr$(10) & [Field2]
  2. Save the Query.
  3. Now, Export the Query containing the single, Calculated Field.
  4. The results should be as follows:
    Expand|Select|Wrap|Line Numbers
    1. xxxx
    2. yyyyyyy
  5. What the Calculated Field does is to concatenate a Carriage Return (Chr$(13))/LineFeed (Chr$(10)) combination which effective places the 2 Fields on separate lines. BTW, the Intrinsic Constant vbCrLf will not work.
  6. Let me know how you make out.
May 26 '08 #2
rajeevs
171 100+
Thank you for the quick response and solution. It works..... great.
Once again thank you so much
May 27 '08 #3
ADezii
8,834 Expert 8TB
Thank you for the quick response and solution. It works..... great.
Once again thank you so much
You are quite welcome.
May 27 '08 #4
rajeevs
171 100+
HI dezyl

I have another prob with the same question. My actual result in the query shaould show the split fields as two different records. As per your advise it works for text file and in the text file it shows two lines. But my actual need is to split that in the query and show as different records.
my data in the table/query shows two fields like field1 xxxxx and field2 as yyyyy
i need the field1 as record1 and field2 as record2. Can you help me how to do this?
Thank yo for the help
Jun 2 '08 #5
ADezii
8,834 Expert 8TB
HI dezyl

I have another prob with the same question. My actual result in the query shaould show the split fields as two different records. As per your advise it works for text file and in the text file it shows two lines. But my actual need is to split that in the query and show as different records.
my data in the table/query shows two fields like field1 xxxxx and field2 as yyyyy
i need the field1 as record1 and field2 as record2. Can you help me how to do this?
Thank yo for the help
I'm not sure if this can be accomplished via SQL, but it can definately be done via VBA code. If you are interested in this approach, let me klnow and I'll see what I can do.
Jun 2 '08 #6
rajeevs
171 100+
Hi ADezil

Thanks for the reply. I am interested to solve the problem in any manner.
Please help me. I can explain you about the scenario
I have a table with multiple fields. My query combine all the fileds and give the result as a single field. like that the query will show reocrds. I need to export that records as a text file. But the text file should have a line(normally six zeros like 000000)before each record,
eg: if my query result is with 4 records like below

wewerrrw wrerwrwrwrk lfjdkljfkdflkdf ldkjflkfjlkfj
jhkdjkfhjdhfjkd kdhfkjdhfkj jkdhfkjdhfjkdh kjdhfkjdhf
kjfhdjkfhjd llkfkljfd lkjsfklfjkl lkjflkjfkl ljfljk lkjflkdjf lkjf
jkhfjkfhjkdfhdjfhdjkfhdjfhdjkfhdjkfhdfhdfhdfjdjjfh djfhdjf

i need that to export as

000000
jhkdjkfhjdhfjkd kdhfkjdhfkj jkdhfkjdhfjkdh kjdhfkjdhf
000000
jhkdjkfhjdhfjkd kdhfkjdhfkj jkdhfkjdhfjkdh kjdhfkjdhf
000000
kjfhdjkfhjd llkfkljfd lkjsfklfjkl lkjflkjfkl ljfljk lkjflkdjf lkjf
000000
jkhfjkfhjkdfhdjfhdjkfhdjfhdjkfhdjkfhdfhdfhdfjdjjfh djfhdjf

Your first reply give me the solution like a single record in two lines.
But i request for a vb code which can insert a pre defined record before each record in the table.
Thank you so much for your kindness and the patience you are showing
Jun 3 '08 #7
ADezii
8,834 Expert 8TB
Hi ADezil

Thanks for the reply. I am interested to solve the problem in any manner.
Please help me. I can explain you about the scenario
I have a table with multiple fields. My query combine all the fileds and give the result as a single field. like that the query will show reocrds. I need to export that records as a text file. But the text file should have a line(normally six zeros like 000000)before each record,
eg: if my query result is with 4 records like below

wewerrrw wrerwrwrwrk lfjdkljfkdflkdf ldkjflkfjlkfj
jhkdjkfhjdhfjkd kdhfkjdhfkj jkdhfkjdhfjkdh kjdhfkjdhf
kjfhdjkfhjd llkfkljfd lkjsfklfjkl lkjflkjfkl ljfljk lkjflkdjf lkjf
jkhfjkfhjkdfhdjfhdjkfhdjfhdjkfhdjkfhdfhdfhdfjdjjfh djfhdjf

i need that to export as

000000
jhkdjkfhjdhfjkd kdhfkjdhfkj jkdhfkjdhfjkdh kjdhfkjdhf
000000
jhkdjkfhjdhfjkd kdhfkjdhfkj jkdhfkjdhfjkdh kjdhfkjdhf
000000
kjfhdjkfhjd llkfkljfd lkjsfklfjkl lkjflkjfkl ljfljk lkjflkdjf lkjf
000000
jkhfjkfhjkdfhdjfhdjkfhdjfhdjkfhdjkfhdfhdfhdfjdjjfh djfhdjf

Your first reply give me the solution like a single record in two lines.
But i request for a vb code which can insert a pre defined record before each record in the table.
Thank you so much for your kindness and the patience you are showing
Will have a solution for you later.
Jun 3 '08 #8
ADezii
8,834 Expert 8TB
  1. I've made the assumption that your Table is named tblTest and that it consists of 2 Fields (TEXT) named [Field1] and [Field2].
  2. Create a New Table named tblResults and a Field within it named [TheField] (TEXT 255).
  3. Run the following code and/or download the attached Test Database to see what is actually happening.
  4. The algorithm is generic in that regardless of the number of Fields in tblTest, each Field will always be written to a single Record in tblResults prefaced by "000000".
  5. Nulls are ignored as evidenced by the missing values in [Field1] ("Five") and [Field2] ("Twelve").
  6. Let me know how you make out, all relevant info is posted below, and the Test Database is attached.
Expand|Select|Wrap|Line Numbers
  1. Dim MyDB As DAO.Database
  2. Dim intNumOfFields As Integer
  3. Dim intFieldCounter As Integer
  4.  
  5. Dim rst_1 As DAO.Recordset
  6. Dim rst_2 As DAO.Recordset
  7.  
  8. Set MyDB = CurrentDb()
  9.  
  10. Set rst_1 = MyDB.OpenRecordset("tblTest", dbOpenForwardOnly)
  11. Set rst_2 = MyDB.OpenRecordset("tblResults", dbOpenDynaset, dbAppendOnly)
  12.  
  13. intNumOfFields = rst_1.Fields.Count
  14.  
  15. 'Delete any pre-existing Records in tblResults
  16. CurrentDb.Execute "Delete * From tblResults", dbFailOnError
  17.  
  18. Do While Not rst_1.EOF
  19.   For intFieldCounter = 0 To intNumOfFields - 1             'iterate Fields/Record
  20.     If Not IsNull(rst_1.Fields(intFieldCounter)) Then       'ignore NULLS
  21.       rst_2.AddNew
  22.         rst_2.Fields(0) = "000000"
  23.       rst_2.Update
  24.       rst_2.AddNew
  25.         rst_2.Fields(0) = rst_1.Fields(intFieldCounter)
  26.       rst_2.Update
  27.     End If
  28.   Next
  29.   rst_1.MoveNext        'advance to the next Record
  30. Loop
  31.  
  32. rst_1.Close
  33. Set rst_1 = Nothing
  34. rst_2.Close
  35. Set rst_2 = Nothing
  36.  
  37. 'Let's see the results!
  38. DoCmd.OpenTable "tblResults", acViewNormal, acReadOnly
  39. DoCmd.Maximize
tblTest
Expand|Select|Wrap|Line Numbers
  1. Field1        Field2
  2. One            Two
  3. Three        Four
  4. Null        Six
  5. Seven        Eight
  6. Nine        Ten
  7. Eleven        Null
  8. Thirteen    Fourteen
  9. Fifteen        Sixteen
tblResults after code execution
Expand|Select|Wrap|Line Numbers
  1. TheField
  2. 000000
  3. One
  4. 000000
  5. Two
  6. 000000
  7. Three
  8. 000000
  9. Four
  10. 000000
  11. Six
  12. 000000
  13. Seven
  14. 000000
  15. Eight
  16. 000000
  17. Nine
  18. 000000
  19. Ten
  20. 000000
  21. Eleven
  22. 000000
  23. Thirteen
  24. 000000
  25. Fourteen
  26. 000000
  27. Fifteen
  28. 000000
  29. Sixteen
Jun 3 '08 #9
rajeevs
171 100+
Hi ADezii

I just tried that code. It works as i reuested. But i need to try once i go to my office whether the text file will work according to my requirement. Thank you so much for the quick reply and the help and support you are providing. I will let you know once i achieve the full result of my database and will contact you if i need further help. Thank you once again
Jun 4 '08 #10
ADezii
8,834 Expert 8TB
Hi ADezii

I just tried that code. It works as i reuested. But i need to try once i go to my office whether the text file will work according to my requirement. Thank you so much for the quick reply and the help and support you are providing. I will let you know once i achieve the full result of my database and will contact you if i need further help. Thank you once again
Exporting tblResults as a Text File as in:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.TransferText acExportDelim, , "tblResults", "C:\Results.txt", False
yields
Expand|Select|Wrap|Line Numbers
  1. "000000"
  2. "One"
  3. "000000"
  4. "Two"
  5. "000000"
  6. "Three"
  7. "000000"
  8. "Four"
  9. "000000"
  10. "Six"
  11. "000000"
  12. "Seven"
  13. "000000"
  14. "Eight"
  15. "000000"
  16. "Nine"
  17. "000000"
  18. "Ten"
  19. "000000"
  20. "Eleven"
  21. "000000"
  22. "Thirteen"
  23. "000000"
  24. "Fourteen"
  25. "000000"
  26. "Fifteen"
  27. "000000"
  28. "Sixteen"
Jun 4 '08 #11
rajeevs
171 100+
Hi AdDezii

Sorry for the delay in reply. I was so busy during the last few days. Your help was so great and it gives me result as i expected. Hope you will continue helping me whenever i stuck with something.

Thank u so much

Regards
Jun 9 '08 #12
ADezii
8,834 Expert 8TB
Hi AdDezii

Sorry for the delay in reply. I was so busy during the last few days. Your help was so great and it gives me result as i expected. Hope you will continue helping me whenever i stuck with something.

Thank u so much

Regards
You are quite welcome and we are always here if and when you need us.
Jun 9 '08 #13

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

Similar topics

14
by: Luka Milkovic | last post by:
Hello, I have a little problem and although it's little it's extremely difficult for me to describe it, but I'll try. I have written a program which extracts certain portions of my received...
2
by: SL_McManus | last post by:
Hi All; I am fairly new to Perl. I have a file with close to 3000 lines that I would like to split out in a certain way. I would like to put the record type starting in column 1 for 2 spaces,...
3
by: rxl124 | last post by:
Hi, room Beginner of learning perl here!! I have question to all, I have below file name datebook.master which contains only 2 lines Mike wolf:12/3/44:144 park ave, paramus: 44000 Sarah kim:...
8
by: uc_sk | last post by:
Hello All I am a newbie to PERL language...If i have a file with data of form abcd 4 {1,2,3} 3 lmn- 3 {12,18,19,22} 4 then i can read them as... ($list $listTotal $set $noElements) = split /...
5
by: NewToThis | last post by:
I am trying to use the split function to bread up lines in a file I am reading from. Some lines are working just fine, but a couple of the lines don't split up the way I would have thought. ...
2
by: Jeremy | last post by:
I have a pretty straightforward database that is designed to record free-form information about products (date, source and a memo field). This is searched and updated via a form. For new records,...
3
by: Jan Hanssen | last post by:
Hi! I have a list of data in a textfile which is tab delimited. Each line is seperated by a VbCrLf. I want to collect this data in a multidimensional string array. I do not wish to use a...
3
by: Ben | last post by:
Hi I am creating a dynamic function to return a two dimensional array from a delimeted string. The delimited string is like: field1...field2...field3... field1...field2...field3......
11
by: Brian | last post by:
I have been working on a data reception system.. I am still finding my way around Javascript, though I am accomplishing much. I just fixed a flaw that was really hard to find. The symptoms are...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...

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.