Solved

How to write a recordset with Access VBA in an XML file

Posted on 2011-09-06
3
388 Views
Last Modified: 2013-11-25
Dear all
I try to write a record or recordset to an empty XML File.
This is my code. But I get run-time error 424.
I would appreciate some help.
Thanks in advance.
Best regards
Frank
 
Sub Write_Recordset_toXMLFile()

Dim strSQL As String
Dim file_name As String
Dim rst As ADODB.Recordset

Set rst = New ADODB.Recordset

    file_name = "C:\Development\Access\Test\xml_test.xml"
    rst.ActiveConnection = CurrentProject.Connection
    strSQL = "SELECT tblLink.ID, tblLink.Frontend, tblLink.FrontendPath FROM tblLink WHERE (((tblLink.ID)=1));"
    rst.Open strSQL

    rs1.Save "file_name", adPersistXML  'Run-Time error '424'

End Sub

Open in new window

0
Comment
Question by:FrankLu
  • 2
3 Comments
 
LVL 6

Accepted Solution

by:
effes earned 500 total points
ID: 36490616
Hi Frank,

I'm don't use VBA too often, but I noticed two things in your code:
1. If it isn't just a typo in your post, try changing "rs1.Save" at the beginning of line 14 to "rst.Save".
2. Remove the quotes around file_name on the same line. The way you're doing it passes the string "file_name" to the function and not the value of the variable file_name.

Line 14 should be like this:

 rst.Save file_name, adPersistXML

I hope that helps,
Frank
0
 

Author Comment

by:FrankLu
ID: 36490783
Hi Effes,

Thank you for your reply. It worked fine.
Best regards
Frank
0
 
LVL 6

Expert Comment

by:effes
ID: 36491544
You're welcome.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
User Beware!  This is a rather permanent solution to removing your email from an exchange server.  The only way to truly go back is to have your exchange administrator restore your mailbox from backups.  This is usually the option of last resort.  A…
Viewers will learn the different options available in the Backstage view in Excel 2013.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now