We help IT Professionals succeed at work.
Get Started
Troubleshooting Question

Exporting Access query to XML

Dale Fye
Dale Fye asked
Last Modified: 2020-10-13
I'm working on some code to write the results of an Access query to an XML file.  If this was going to be a flat file, then I'd be done, but I need to be able to provide detail info, something like:
        <Street>112 Test Road</Street>
        <City>New York</City>
I've configured my column names like:
I'm trying to devise a function which will parse the address field names into a structure which looks like the above. I'm totally flexible and can rewrite the query to return the column names differently, but this seemed like it would work.  

I'm just having a brain cramp and cannot get this figured out.

If it was just this one case (address), I'd do something like:
If fields(n).Name = "Address|Street" Then
    Print #1, "<Address>"
    Print #1, "    <Street>" & rs(fields(n).name) & "</Street>
elseif fields(n).name = "Address|City" Then
    Print #1, "    <City>" & rs(fields(n).name) & "</City>
Elseif fields(n).name = "Adderss|State" Then
    Print #1, "    <State>" & rs(fields(n).name) & "</State>
    Print #1, "<Address>"
end if
 But I would like to be able to make this more generic so that if I pass a function the values:
Call WriteToXML("Case_Num", 1)
Call WriteToXML("Address|Street", "113 Test Road")
Call WriteToXML("Address|City", "New York")
Call WriteToXML("Address|State", "NY")
Call WriteToXML("SomethingElse", 3)
it would write to the XML file similar to my code segment.  I don't know enough about XML to write my own style sheet.  BTW, there will be cases where the data is nested 3 deep.

Watch Question
Owner, Dev-Soln LLC
Top Expert 2010
This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE