Merge data into existing .txt document and save into newly createdfolder with new name and ext.

R

ronpassaro

Hi all,

Here's a simplified example of what I would like to accomplish.

1. I have a .txt file containing the following xml code:

<TYPE>[FILETYPE]</TYPE>
<ID>[IDNUMBER]</ID>
<OWNER>
<OWNER-FN>[FIRSTNAME]</OWNER-FN>
<OWNER-LN>[LASTNAME]</OWNER-LN>
<OWNER-ZIP>[ZIPCODE]</OWNER-ZIP>
</OWNER>

2. I would like to replace the variables ([FILETYPE], [IDNUMBER],
[FIRSTNAME], [LASTNAME], [ZIPCODE]) with the corresponding data from
an Access table of mine.

3. I would like to save the newly updated content to a new folder with
a new name and extension as follows:

a. create a folder under a specified directory and name it the same as
the "[IDNUMBER]" variable, which is unique. SO if the [IDNUMBER] field
= "123456", the folder would be named "123456".

b. Inside that folder I would like to name the updated content (the
text file merged with the table data) after the "[IDNUMBER]" variable,
and have the extension be ".tre" (made up extension). So if the
[IDNUMBER] field = "123456", the resulting file would be "123456.tre",
saved withing the "123456" folder created in step 3a.

I apologize if this request was posted in the wrong location, but I
thought a query might be involved here as most merge instructions I've
seen involve queries.

Your help in this matter is greatly appreciated!
 
M

MGFoster

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You can use the Scripting library (in Tools > References in the VBA
window) to use the FileSystemObject class to create the folder and file
(CreateFolder and CreateTextFile).

Use the OPEN "template file.xml" FOR INPUT AS #1 and read the whole file
into one variable - strTemplate. Then use the Replace() function to
replace the [FILETYPE], [IDNUMBER],[FIRSTNAME], [LASTNAME], [ZIPCODE]
fields in the string (use a Recordset to loop thru the data):

Replace(strTemplate, [FILETYPE], rs!col_1)
Replace(strTemplate, [IDNUMBER], rs!col_2)
... etc. ...

Then write the updated template to your new file using the
FileSystemObject.TextStream.

Repeat for each row (record) in the data table.

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
** Respond only to this newsgroup. I DO NOT respond to emails **

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBSMbDF4echKqOuFEgEQJVnwCfUVKx7jDe/CVuwIwtK6I/VjYnNj4AoLPo
gRuIbySYrNjKL8ZhY69X3VPo
=4PvZ
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top