writing to a file (1 Viewer)

Denmarkacceess

New member
Local time
Today, 18:43
Joined
Feb 4, 2014
Messages
6
Hello

I have a table that looks like this:
Field1 = FirstName
Field2 = Lastname
Field3 = Address

I want the writing to a file that looks like this:
<statics>
<Contact>
<Firstname></FirstName>
<Lastname></Lastname>
<Address></Address>
</contact>
</statics>

etc.

it can be done via vba?
 

Cronk

Registered User.
Local time
Tomorrow, 03:43
Joined
Jul 4, 2013
Messages
2,772
In another post, you've asked to do the same thing via XML using XSD, and been advised to google.

You can write a simple formatted XML by just outputting text. Google vba output to text file

Code:
Open recordset, rst
n= freefile
open file as 1
Write #n,"<statics> "

rst.movefirst
do while not rst.eof
  Write #n, "<Contact>"
   Write #n,"<Firstname>" & rst!FirstName & "</Firstname>"
   ...
   rst.movenext
loop
Write #n,"/<statics>"
close file
 

Denmarkacceess

New member
Local time
Today, 18:43
Joined
Feb 4, 2014
Messages
6
roger

but I need some more help, try to insert into vba, but jeg have a problem with "openrecordset, rst
 

Denmarkacceess

New member
Local time
Today, 18:43
Joined
Feb 4, 2014
Messages
6
Dim rst As DAO.Recordset
Open "C:\names.xml" For Output As #1
Set rst = CurrentDb.OpenRecordset("SELECT * FROM tabel1", dbOpenSnapshot)
Print #1, "<statics>"

rst.MoveFirst


Do While Not rst.EOF

Print #1, "<Contact>"
Print #1, "<Firstname>" & rst!fornavn & "</Firstname>"
Print #1, "<Lastname>" & rst!efternavn & "</Lastname>"
Print #1, "<Address>" & rst!adresse & "</Address>"
Print #1, "</Contact>"
rst.MoveNext
Loop
Print #1, "</statics>"
rst.Close
Set rst = Nothing
Close #1
 

Users who are viewing this thread

Top Bottom