Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-09-06
3
Medium Priority
?
399 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 2000 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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…

926 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