473,383 Members | 1,716 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

ACCESS VBA to Write Query Results to XML files

Hello;

I am trying to use Access VBA to write each record in a query to its own individual XML file. That is, each record represents one XML file which will then be sent to a SharePoint Form Library.

I am unsure how to tackle this problem. I tried to send my QueryResults to InfoPath, but all the records appear as repeating sections in a single XML file. Therefore, that choice doesn't seem to work. So now I'm wondering if I can bypass the InfoPath step and just write directly out of Access to the SharePoint Form Library.

For Reference, I have the MS-ACCESS 2003 Bible by Wiley Press.

Thanks,
Gregg
Apr 9 '07 #1
5 11093
MMcCarthy
14,534 Expert Mod 8TB
Hi Gregg

I'm not sure how to connect to the sharepoint form library although someone else may know.

However, to write out records individually to a series of text file for example you could do the following ...
Expand|Select|Wrap|Line Numbers
  1. Function createTxtFile(path As String)
  2. Dim fs As Object
  3. Dim f As Object
  4.  
  5.     Set fs = CreateObject("Scripting.FileSystemObject")
  6.     Set f = fs.CreateTextFile(path, True)
  7.     f.Close
  8.  
  9. End Function
  10.  
  11. Function writeFiles()
  12. Dim db As DAO.Database
  13. Dim rs As DAO.Recordset
  14. Dim frfile As Integer
  15. Dim fileName As String
  16. Dim fline As String
  17. Dim i As Integer
  18.  
  19.    Set db = CurrentDb
  20.    Set rs = db.OpenRecordset("QueryName")
  21.    i = 1
  22.    rs.Move First
  23.    Do Until rs.EOF
  24.       createTxtFile("c:\file" & i " ".txt")
  25.       fileName = "c:\file" & i " ".txt"   
  26.       fline = rs!Field1 & ", " & rs!Field2 & ", " & rs!Field3 ' etc.
  27.  
  28.    'open the text file to be written to
  29.    frfile = FreeFile()
  30.    Open fileName For Output Access Write As #frfile
  31.  
  32.         Print #frfile, fline
  33.  
  34.     Close #frfile
  35.    i = i + 1
  36. Loop
  37.  
  38. End Function
  39.  
Apr 10 '07 #2
pks00
280 Expert 100+
If u have the 2003 Bible, I assume u are using Acces 2003 ?
Ok, u can use ExportXML function

this is what u can do
lets say u had a query called qryA and it has this

select field1,field2,field3,field4 from mytable

where field1 is the primary key

What u need to do is create a new query, call it say, qryABase
all it has is SELECT * FROM QryA

Here is sample code which now goes thru qryA, setting and exporting qryABase as xml


Expand|Select|Wrap|Line Numbers
  1. Public Sub ExportRecsToXML()
  2.     Dim rs As DAO.Recordset
  3.     Dim qdf As DAO.QueryDef
  4.  
  5.     'Point to my temp query
  6.     Set qdf = CurrentDb.QueryDefs("qryABase")
  7.  
  8.     'Open recordset to my query
  9.     Set rs = CurrentDb.OpenRecordset("qryA")
  10.  
  11.     Do While rs.EOF = False
  12.  
  13.         'Set temp query to return that one record only
  14.         qdf.SQL = "SELECT * FROM qryA WHERE Field1 = " & rs!Field1
  15.  
  16.         'Now dump that temp query as a xml
  17.         Application.ExportXML acExportQuery, qdf.Name, "C:\tsdn\" & rs!Field1 & ".xml"
  18.  
  19.         rs.MoveNext
  20.     Loop
  21.     rs.Close
  22.     Set rs = Nothing
  23.  
  24. End Sub
  25.  
Apr 10 '07 #3
Okay, this worked really well. The only issue now is that the Parameter Value dialog box appears for every single record being exported. How can I satisfy the value so that I don't need to enter it each time? Thanks!
May 6 '07 #4
MMcCarthy
14,534 Expert Mod 8TB
Okay, this worked really well. The only issue now is that the Parameter Value dialog box appears for every single record being exported. How can I satisfy the value so that I don't need to enter it each time? Thanks!
Put the value in a textbox on a form. Enter the value on the form and keep the form open when running the code. Change the criteria of the query from an input box to reference the textbox on the form.

Mary
May 6 '07 #5
Hi;

Thanks for the solution. I ended up doing it another way because I wasn't sure how to manipulate the input user forms. What I did instead was I wrote a single record to a temp table that I created within Access. I then used the temp table as the DataSource argument for the ExportXML object. Then I delete the temp record and read the next record from the primary table until EOF.

Not sure how valid an approach that is, but it seems to be working for my needs right now.

Thanks,
Gregg
May 7 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: lawrence | last post by:
I've been bad about documentation so far but I'm going to try to be better. I've mostly worked alone so I'm the only one, so far, who's suffered from my bad habits. But I'd like other programmers...
2
by: Angelos Karantzalis | last post by:
Hi guys, for a while now, we've been flirting with the idea of having a single component in our app that handles all the plumbing for our Db calls ( creating connections, Commands & Parametes...
4
by: Bon | last post by:
Hello all Would it be possible to migrate the MS Access 2000 to MS SQL Server 2000? My application is using MS Access 2000 as database and as user interface such as forms. Now, I want to...
2
by: Mattyboy | last post by:
Guys I have built a database with saved queries that runs fine in Access but when I call it from the web using ASP, an exception occurs. I have tried multiple ways of testing the databases with...
4
by: cameron | last post by:
I have always been under the impression that LDAP was optimized for speed. Fast queries, fast access, slower writes. I have a block of data in LDAP and in SQL. Exact same data. The query is fast...
12
by: VMI | last post by:
For some reason, the process of retrieving data (about 20 records) from an Access table that has 400K records to a dataTable is taking over 3 mins. to complete. Below is my code to connect to the...
16
by: JoeW | last post by:
I'm utilizing a database that I created within MS Access within a program I've created in VB.NET. I am using the VB front end to navigate the information, but want to be able to print a report,...
6
by: venmore | last post by:
Hi Can someone please point in the right direction. I have an XML file that gets updated every 4 hours on a web server. I can check the XML modification time in ASP and compare to the databse....
2
by: Rich P | last post by:
The problem is with the ODBC connection - in general. If you are going to be using Access as a front end for a Sql Server backend - you will have more consistent/better results using ADO instead...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.