473,383 Members | 1,963 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,383 software developers and data experts.

combining multiple files

Hi All,

I have 10 text files in one folder. I want combine selected files in to one text using access. Can any one help me on this?

Thanks in advance,
Raghav

**************** (e-mail removed as per site rules)
Jun 9 '07 #1
8 4709
ADezii
8,834 Expert 8TB
Hi All,

I have 10 text files in one folder. I want combine selected files in to one text using access. Can any one help me on this?

Thanks in advance,
Raghav

raghavrc@gmail.com
You can actually Shell out and use the DOS Copy Command to concatenate all 10 Files into 1 as in:
Expand|Select|Wrap|Line Numbers
  1. C:\copy File1.txt+File2.txt+File3.txt+File4.txt+File5.txt+File6.txt+File7.txt+File8.txt+File9.txt+File10.txt DestinationFile.txt
Jun 9 '07 #2
Use the filesystemobject (needs a ref to MS scripting runtime) to create a ref to the folder.

eg
Expand|Select|Wrap|Line Numbers
  1. set fso = new filesystemobject
  2.  
  3. set folders = fso.getfolder . . . . .wherever it is
  4.  
  5. Then open a textstream object.
  6.  
  7. eg set file1 = fso.createtextstream
loop through the files in the folder and add the text to the ts object using file1.writeline

Expand|Select|Wrap|Line Numbers
  1. for each file in folder1
  2.   ...add text lines to consolidating file
  3. next file
Jun 9 '07 #3
You can actually Shell out and use the DOS Copy Command to concatenate all 10 Files into 1 as in:
Expand|Select|Wrap|Line Numbers
  1. C:\copy File1.txt+File2.txt+File3.txt+File4.txt+File5.txt+File6.txt+File7.txt+File8.txt+File9.txt+File10.txt DestinationFile.txt
Hi. thanks for your reply.
Now I will explain real situation in my request.
In the MS-Access form has multiple check boxes for each text file. All text files located in one signle folder. User will select the check boxes which he wants to combine. when the user click a command button it should create a new text file with all selected text files data.

I am new to access coding. I am working in Mainframes but having small work in access.

Thanks in advance,
Raghav
Jun 11 '07 #4
ADezii
8,834 Expert 8TB
Hi. thanks for your reply.
Now I will explain real situation in my request.
In the MS-Access form has multiple check boxes for each text file. All text files located in one signle folder. User will select the check boxes which he wants to combine. when the user click a command button it should create a new text file with all selected text files data.

I am new to access coding. I am working in Mainframes but having small work in access.

Thanks in advance,
Raghav
I'll work on it but give me a little time - I'm not really sure how to approach this.
Jun 11 '07 #5
ADezii
8,834 Expert 8TB
Hi. thanks for your reply.
Now I will explain real situation in my request.
In the MS-Access form has multiple check boxes for each text file. All text files located in one signle folder. User will select the check boxes which he wants to combine. when the user click a command button it should create a new text file with all selected text files data.

I am new to access coding. I am working in Mainframes but having small work in access.

Thanks in advance,
Raghav
I have arrived at a solution for you - will be posting it either later today or this evening.
Jun 11 '07 #6
ADezii
8,834 Expert 8TB
Hi. thanks for your reply.
Now I will explain real situation in my request.
In the MS-Access form has multiple check boxes for each text file. All text files located in one signle folder. User will select the check boxes which he wants to combine. when the user click a command button it should create a new text file with all selected text files data.

I am new to access coding. I am working in Mainframes but having small work in access.

Thanks in advance,
Raghav
Since you do work with Mainframes, and are not that familiar with Access, I took the most basic approach possible, Low Level File I/O Functions. Yes, believe it or not, they are still around and you don't have to worry about setting any References or what Version of Access you are running. I wrote the code for 3 Check Boxes (chkOne, chkTwo, and chkThree) but I am sure that that you will be able to produce the remaining code from these 3. Simply copy and paste this code into the Click() Event of a Command Button, rename any Controls and/or File Paths/Names as appropriate, and you are ready to go. It is not very elegant - but it is functional. Any further questions, feel free to ask.

Expand|Select|Wrap|Line Numbers
  1. 'If none of the Check Boxes are Checked, get outta Dodge!
  2. If Not Me![chkOne].Value And Not Me![chkTwo].Value And Not Me![chkThree].Value Then
  3.   Exit Sub
  4. End If
  5.  
  6. Dim strFilesPath As String, strSingleLine As String
  7. Dim strDestFileName As String, intResponse As Integer
  8.  
  9. 'Specify the Path to your Files here
  10. strFilesPath = "C:\Test\"
  11. strDestFileName = strFilesPath & "Destination.txt"      'Target File
  12.  
  13. If Dir$(strDestFileName, vbNormal) <> "" Then
  14.   intResponse = MsgBox(strDestFileName & " already exists. DELETE this File?", _
  15.                 vbYesNo + vbQuestion + vbDefaultButton1, "DELETE Confirmation")
  16.     If intResponse = vbYes Then
  17.       Kill strDestFileName
  18.     End If
  19. End If
  20.  
  21. Open strDestFileName For Append As #255
  22.  
  23. 'If this Check Box is selected, Append contents to Destination.txt
  24. If Me![chkOne].Value Then
  25.   Open strFilesPath & "Test1.txt" For Input As #1
  26.     Do While Not EOF(1)
  27.       Line Input #1, strSingleLine
  28.       Print #255, strSingleLine
  29.     Loop
  30.     Close #1
  31. End If
  32.  
  33. If Me![chkTwo].Value Then
  34.   Open strFilesPath & "Test2.txt" For Input As #2
  35.     Do While Not EOF(2)
  36.       Line Input #2, strSingleLine
  37.       Print #255, strSingleLine
  38.     Loop
  39.     Close #2
  40. End If
  41.  
  42. If Me![chkThree].Value Then
  43.   Open strFilesPath & "Test3.txt" For Input As #3
  44.     Do While Not EOF(3)
  45.       Line Input #3, strSingleLine
  46.       Print #255, strSingleLine
  47.     Loop
  48.     Close #3
  49. End If
  50.  
  51.  
  52. Close #255
Jun 11 '07 #7
Thanks you very much! I will work on this code and let you know if I require any additional help on this.

Thanks again.
Jun 12 '07 #8
FishVal
2,653 Expert 2GB
Or something like this allowing user to select multiple files via FileDialog.
NB. "Microsoft Office xx.x Object Librar" has to be referenced

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub btnPickFiles_Click()
  3.  
  4. Dim dlgPickFiles As Office.FileDialog
  5. Dim strDestFilePath As String, strSingleLine As String
  6. Dim strDestFileName As String, intResponse As Integer
  7.  
  8. Set dlgPickFiles = Application.FileDialog(msoFileDialogFilePicker)
  9.  
  10. With dlgPickFiles
  11. .AllowMultiSelect = True
  12. With .Filters
  13. .Clear
  14. .Add "Text file", "*.txt"
  15. End With
  16. .Show
  17. End With
  18.  
  19.  
  20. strDestFilePath = "C:\Test\"
  21. strDestFileName = strFilesPath & "Destination.txt" 'Target File
  22.  
  23. If Dir$(strDestFileName, vbNormal) <> "" Then
  24. intResponse = MsgBox(strDestFileName & " already exists. DELETE this File?", _
  25. vbYesNo + vbQuestion + vbDefaultButton1, "DELETE Confirmation")
  26. If intResponse = vbYes Then
  27. Kill strDestFileName
  28. End If
  29. End If
  30.  
  31. Open strDestFileName For Append As #255
  32.  
  33. For Each FileSelected In dlgPickFiles.SelectedItems
  34.  
  35. Open FileSelected For Input As #1
  36. Do While Not EOF(1)
  37. Line Input #1, strSingleLine
  38. Print #255, strSingleLine
  39. Loop
  40. Close #1
  41.  
  42. Next
  43.  
  44. Close #255
  45.  
  46. Set dlgPickFiles = Nothing
  47.  
  48. End Sub
  49.  
  50.  
Good luck.

PS. Destination file may be also choosed via FileDialog.
Jun 12 '07 #9

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

Similar topics

8
by: Ilan | last post by:
Hi all I need to add data from two Excel sheets (both on the same workbook) to an existing table in my SQL DB. The problem is that each sheet holds different fields for the same record, though...
0
by: BaKMaN | last post by:
I am using ASP/VBScript to produce a XML file based on a AccesDB query (using adPersistXML) and include a XSL, by itself this works nicely. Is it possible to combine 2 separate queries into one...
3
by: alwayswinter | last post by:
I currently have a form where a user can enter results from a genetic test. I also have a pool of summaries that would correspond to different results that a user would enter into the form. I...
1
by: Heather | last post by:
I know this is a painful question and I have searched the group for past responses and none of the responses seem to cover my specific need. We have a table that contains fields like ID, Yr,...
3
by: Flip | last post by:
I'm looking at the O'Reilly Programming C# book and I have a question about extending and combining interfaces syntax. It just looks a bit odd to me, the two syntaxes look identical, but how does...
1
by: Adam Clauss | last post by:
Alright, I have a need to combine 2 (or possibly more - figure if I can get two working, more won't be hard) .wav files into one .wav file. Now, it is relatively easy enough for me to read in the...
4
by: Qwert | last post by:
Hello, is there a way to combine multiple files into 1 file with VB.NET? Example: Dim MyList As New ArrayList() MyList.Add("File1.txt") MyList.Add("File2.doc") Pack(MyList ,...
3
by: Odawg | last post by:
Hello All Database (Access) Guru's, I am a novice when it comes to databases and I know enough to get simple information for my needs. With that said, I was given an opportunity for improvement...
2
by: rpeacock | last post by:
I have a function that takes a field with values separated by commas within the field and splits them to multiple rows. Example: Field - Interior Value - abc,def,efg,ghi Output: ID Item 1 ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.