By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,197 Members | 1,207 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,197 IT Pros & Developers. It's quick & easy.

combining multiple files

P: 3
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
Share this Question
Share on Google+
8 Replies


ADezii
Expert 5K+
P: 8,638
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

P: 7
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

P: 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
Expert 5K+
P: 8,638
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
Expert 5K+
P: 8,638
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
Expert 5K+
P: 8,638
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

P: 3
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
Expert 2.5K+
P: 2,653
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

Post your reply

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