Solved

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

Posted on 2011-09-06
3
390 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
Viewers will learn how to maximize accessibility options in an Excel workbook for users with accessibility issues.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

803 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