Solved

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

Posted on 2011-09-06
3
392 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SSIS 2010 Convert to SSIS 2013 On Different Box 3 65
SCCM 2012 - Backup and Recovery Best Practice 2 142
Microsoft Access 2010 Question 2 92
Windows ICD FFU Issue 4 107
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

752 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