Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...You have made an incredible site which is truly a great help to me in solving problems. A tip of my hat to you!..."

Geography

Where in the world do Tek-Tips members come from?

Output to XML button not working anymore...Helpful Member! 

Triacona (TechnicalUser)
24 Feb 12 8:31
Dear All,

Thank you all for a great forum!smile

I have the following problem.

The code below is giving me a

Quote (error):

Run-time error 31532.
EH Reports was unable to export the data.
Code for button below.

CODE

Private Sub CpOutputQueryToXML_Click()
'*COMMERCIAL PREMISES CP OUTPUT TO XML BUTTON

Dim stDocName As String
    stDocName = Me!ListCP.Column(2)

Dim sFullPath As String
    sFullPath = txtPath & stDocName & ".xml"

Application.ExportXML acExportQuery, stDocName, sFullPath & ".xml"
 
 
End Sub

I have tried changing a number of things but to not avail...
The query for this export also takes a value off the MainScreen form.

CODE

Like "*" & [forms]![MainScreen]![SubFrmInput].[form]![cmbCpTradeAs] & "*"

Please help I have been banging my head on this onebanghead
Thank you for all the forthcoming helpbigsmile

Thank you,

Kind regards

Triacona

Triacona (TechnicalUser)
24 Feb 12 9:46
Dear All,

I hav also tried..

CODE

stDocName = Me.ListCP.Column(2)

Thank you,

Kind regards

Triacona

Triacona (TechnicalUser)
24 Feb 12 9:59
Dear All,

I have figured out what the problem is, but I don't know how to fix it.

If I remove

CODE

Like "*" & [forms]![MainScreen]![SubFrmInput].[form]![cmbCpTradeAs] & "*"
Then the button works...
If I have the code above in the query; then even though the form MainScreen has the data in it, the prompt that appears after I click on the OutputToXml button, is the same code as above?!

Please help this is a strange error.
Do I have to declare the above code in the button code??

Thank you for your helpsmile

Thank you,

Kind regards

Triacona

Triacona (TechnicalUser)
24 Feb 12 10:22
Dear all,

update I have also removed the ".xml" which just added the name.

CODE

sFullPath = txtPath & stDocName & ".xml"

Thanks smile

Thank you,

Kind regards

Triacona

Triacona (TechnicalUser)
27 Feb 12 5:50
Dear All,

Any thoughts?

Thank you smile

Thank you,

Kind regards

Triacona

PHV (MIS)
27 Feb 12 6:03
Triacona (TechnicalUser)
27 Feb 12 7:33
Dear PHV,

Thanks for your reply, really appreciated bigsmile

I don't open the query before exporting it...

Normally it used to work until I put the criteria in the query.

Is there any way to declare the criteria in the export?

Would I put in a Docmd.open query stdocname and then the export to XML code?

Thanks again for your helpsmile

Thank you,

Kind regards

Triacona

Triacona (TechnicalUser)
27 Feb 12 9:38
Dear PHV,

Thanks again for your help.

I have tried this and it still gives me an Error.

CODE


DoCmd.OpenQuery stDocName, acViewNormal
Application.ExportXML acExportQuery, stDocName, sFullPath & ".xml"

Quote (Error:):

Run-time error '31532' Reports unable to export data

Thank you,

Kind regards

Triacona

Triacona (TechnicalUser)
27 Feb 12 9:45
Dear PHV,

Update :
I click debug and it highlights the following code.

CODE



Application.ExportXML acExportQuery, stDocName, sFullPath & ".xml"
The values in the variables are the following:
acExportQuery = 1
stDocName = CpSotFsaXml (correct)
sFullPath = G:\EH\CpSotFsaXml (correct)

I really don't know what could be causing the error, as the values are correct, the only value I am not certain about is acExportQuery = 1.

Your help would be greatly appreciated!smile

Thank you,

Kind regards

Triacona

Taaner (Programmer)
27 Feb 12 10:36
The constant acExportQuery always equals 1, it defines the type you want to export. In this case a query, that should be okay.

So what can be the problem:
1. the query does not work for any reason
2. the file you want to export to is not accessible

I should run the query itself, and if you have a result, and than export the result manually to the xml.

One of the possible reasons is that you run the program in sandbox mode. In Access 2007 the function ExportXML is blocked in the sandbox mode (dont know about 2010).
http://office.microsoft.com/en-us/access-help/functions-and-properties-in-access-2007-blocked-by-sandbox-mode-HA001230190.aspx
Triacona (TechnicalUser)
27 Feb 12 11:28
Dear Taaner,

Thank you very much for your responsesmile

The query works as I run that from a form using a different button.

It runs the export when there are no criteria in the query.

It also fails exporting when there is criteria and I try to export it via File -> Export and then I choose XML; it askes for the criteria, as if it doesn't see the form and if nothing is entered it fails and if something is entered it does not bring the correct data in...

This is quite a weird error....

I am wondering if I would need to declare the SQL in the code and have a dynamic query?

Any further thoughts or help are greatly appreciatedsmile

Thank you!

Thank you,

Kind regards

Triacona

Triacona (TechnicalUser)
27 Feb 12 11:29
Oh yes before I forget, I am running MS Access 2003

Thank you,

Kind regards

Triacona

Triacona (TechnicalUser)
28 Feb 12 9:56
Dear all,

Below is the code I am using and I am still getting

Quote (error 31532):

Run-time error '31532' Reports unable to export data

CODE

Private Sub CpOutputQueryToXML_Click()
'*COMMERCIAL PREMISES CP OUTPUT TO XML BUTTON

    Dim stDocName As String
         stDocName = ListCP.Column(2)
    Dim sFullPath As String
         sFullPath = txtPath & stDocName
        
        DoCmd.OpenQuery stDocName, acViewNormal
        Application.ExportXML acExportQuery, stDocName, sFullPath & ".xml"
        DoCmd.Close
        
End Sub

I have no idea what the problem is, please helpsmile

Thank you so much!

Thank you,

Kind regards

Triacona

PHV (MIS)
28 Feb 12 10:20
What about this if you remove the criteria in the query ?

CODE

Private Sub CpOutputQueryToXML_Click()
'*COMMERCIAL PREMISES CP OUTPUT TO XML BUTTON
Dim stDocName As String
stDocName = ListCP.Column(2)
Dim sFullPath As String
sFullPath = txtPath & stDocName
Dim strWhere As String
strWhere = "[your field name here] Like '*" & Forms!MainScreen!SubFrmInput.Form!cmbCpTradeAs & "*'"
Application.ExportXML acExportQuery, stDocName, sFullPath & ".xml", , , , , , strWhere
End Sub

Hope This Helps, PH.
FAQ219-2884: How Do I Get Great Answers To my Tek-Tips Questions?
FAQ181-2886: How can I maximize my chances of getting an answer?

Triacona (TechnicalUser)
28 Feb 12 11:29
Dear PHV,

Thank you very much for your help smile

I have tried your way, I removed the criteria out of the query first, then tested it and that worked...

I then did the following..

CODE

Private Sub CpOutputQueryToXML_Click()
'*COMMERCIAL PREMISES CP OUTPUT TO XML BUTTON

    Dim stDocName As String
         stDocName = ListCP.Column(2)
    Dim sFullPath As String
         sFullPath = txtPath & stDocName
        
    Dim sWhere As String
         sWhere = "TRADEAS Like '*" & Forms!MainScreen!SubFrmInput.Form!cmbCpTradeAs & "*'"
       

        Application.ExportXML acExportQuery, stDocName, sFullPath & ".xml", , , , , , sWhere

    
End Sub    

The code above does not give an error message, but produces an incorrect xml file with just one field, the date and time it was created...

TRADEAS being the field in the query that is picked from a dropdown on the form MainScreen.

I would like to keep the criteria in the query as it is used on other buttons, (Run Query and Export Query to Excel)

So I am wondering if there is a way just for the xml button to create a dynamic query in the code so that there has to be no changes to other parts of the program.

CODE

SELECT SotQ5.REFVAL, SotQ5.TRADEAS, SotQ5.Con, SotQ5.CONTACT, SotQ5.UPRN, SotQ5.Add, SotQ5.POSTCODE, SotQ5.InspTyp, SotQ5.SCORE, SotQ5.TARGET_DATE, SotQ5.MainUse, SotQ5.MainUseDsc, SotQ5.SotUseDsc, SotQ5.[Band], SotQ5.CPCONTTYPE, SotQ5.CONTADD, SotQ5.ACTUAL_DATE, SotQ5.QScore AS Q5, SotQ6.QScore AS Q6, SotQ7.QScore AS Q7, SotRating.TotalBcScore, SotRating.Rating, SotRating.LaemsUse AS businesstype, SotQ5.AddLine, AddressOnly(SotQ5.ADDRESS) AS AddO
FROM SotRating INNER JOIN ((SotQ5 INNER JOIN SotQ6 ON SotQ5.REFVAL = SotQ6.REFVAL) INNER JOIN SotQ7 ON SotQ6.REFVAL = SotQ7.REFVAL) ON SotRating.REFVAL = SotQ5.REFVAL
WHERE (((SotQ5.TRADEAS) Like "*" & [forms]![MainScreen]![SubFrmInput].[form]![cmbCpTradeAs] & "*"))
ORDER BY SotQ5.TRADEAS;

As you can see above, that is the sql for my query.

So if I will try to setup, something in the code that does so...

If you know of an easier way, that would be great! bigsmile
 

Thank you,

Kind regards

Triacona

Triacona (TechnicalUser)
1 Mar 12 7:12
Dear All,

I have now tried the following...

CODE

Private Sub CpOutputQueryToXML_Click()
'*COMMERCIAL PREMISES CP OUTPUT TO XML BUTTON

    Dim db As DAO.Database
    Dim qdf As DAO.QueryDef
    Dim SQL As String
    'Dim Pack As String
    Dim stDocName As String
        stDocName = ListCP.Column(2)
    Dim sFullPath As String
        sFullPath = txtPath & stDocName
    'Dim sWhere As String
        'sWhere = "[TRADEAS] Like '*" & Forms!MainScreen!SubFrmInput.Form!cmbCpTradeAs & "*'"

      
    Set db = CurrentDb
    Set qdf = db.QueryDefs("CpSotFsaXml")

SQL = "SELECT SotQ5.REFVAL, SotQ5.TRADEAS, SotQ5.Con, SotQ5.CONTACT, SotQ5.UPRN, SotQ5.Add, " & _
        "SotQ5.POSTCODE, SotQ5.InspTyp, SotQ5.SCORE, SotQ5.TARGET_DATE, SotQ5.MainUse, SotQ5.MainUseDsc, " & _
        "SotQ5.SotUseDsc, SotQ5.Band, SotQ5.CPCONTTYPE, SotQ5.CONTADD, SotQ5.ACTUAL_DATE, SotQ5.QScore AS Q5, " & _
        "SotQ6.QScore AS Q6, SotQ7.QScore AS Q7, SotRating.TotalBcScore, SotRating.Rating, " & _
        "SotRating.LaemsUse AS businesstype, SotQ5.AddLine, AddressOnly(SotQ5.ADDRESS) AS AddO " & _
        "FROM SotRating " & _
        "INNER JOIN ((SotQ5 INNER JOIN SotQ6 ON SotQ5.REFVAL = SotQ6.REFVAL) " & _
        "INNER JOIN SotQ7 ON SotQ6.REFVAL = SotQ7.REFVAL) ON SotRating.REFVAL = SotQ5.REFVAL " & _
        "WHERE (((SotQ5.TRADEAS) Like " * " & Forms!MainScreen!SubFrmInput.Form!cmbCpTradeAs & " * ")) " & _
        "ORDER BY SotQ5.TRADEAS "

        Debug.Print SQL
        
        Application.ExportXML acExportQuery, stDocName, sFullPath & ".xml" ', , , , , , sWhere
        
        qdf.Close
        
    Set qdf = Nothing
    Set db = Nothing
    

End Sub

The above code gives me the following error..

Quote (Run-time error '13':):


Type mismatch
This is due to the code above highlighted in yellow...
If I take it out I get the same error

Quote (Run-time error '31532':):


Reports unable to export data  

So back to square 1! mooo
Am I coding the SQL code highlighted in yellow properly?
Please help this problem is doing my head inbanghead
Thank you bigsmile2thumbsup

Thank you,

Kind regards

Triacona

Triacona (TechnicalUser)
6 Mar 12 7:10
Any thoughts anyone?
Any help would be greatly appreciated, I am quite stuck on this problem...
Thank you smile

Thank you,

Kind regards

Triacona

Taaner (Programmer)
6 Mar 12 7:18
You should solve that type mismatch first by analysing the sql-statement at runtime.
Helpful Member!  PHV (MIS)
6 Mar 12 8:23

CODE

Private Sub CpOutputQueryToXML_Click()
'*COMMERCIAL PREMISES CP OUTPUT TO XML BUTTON
    Dim db As DAO.Database
    Dim qdf As DAO.QueryDef
    Dim SQL As String
    Dim stDocName As String
        stDocName = ListCP.Column(2)
    Dim sFullPath As String
        sFullPath = txtPath & stDocName
    Set db = CurrentDb
    Set qdf = db.QueryDefs("CpSotFsaXml")
SQL = "SELECT SotQ5.REFVAL, SotQ5.TRADEAS, SotQ5.Con, SotQ5.CONTACT, SotQ5.UPRN, SotQ5.Add, " & _
        "SotQ5.POSTCODE, SotQ5.InspTyp, SotQ5.SCORE, SotQ5.TARGET_DATE, SotQ5.MainUse, SotQ5.MainUseDsc, " & _
        "SotQ5.SotUseDsc, SotQ5.Band, SotQ5.CPCONTTYPE, SotQ5.CONTADD, SotQ5.ACTUAL_DATE, SotQ5.QScore AS Q5, " & _
        "SotQ6.QScore AS Q6, SotQ7.QScore AS Q7, SotRating.TotalBcScore, SotRating.Rating, " & _
        "SotRating.LaemsUse AS businesstype, SotQ5.AddLine, AddressOnly(SotQ5.ADDRESS) AS AddO " & _
        "FROM SotRating " & _
        "INNER JOIN ((SotQ5 INNER JOIN SotQ6 ON SotQ5.REFVAL = SotQ6.REFVAL) " & _
        "INNER JOIN SotQ7 ON SotQ6.REFVAL = SotQ7.REFVAL) ON SotRating.REFVAL = SotQ5.REFVAL " & _
        "WHERE (((SotQ5.TRADEAS) Like '*" & Forms!MainScreen!SubFrmInput.Form!cmbCpTradeAs & "*')) " & _
        "ORDER BY SotQ5.TRADEAS "
        Debug.Print SQL
        qdf.SQL = SQL
        db.QueryDefs.Refresh
        Application.ExportXML acExportQuery, "CpSotFsaXml", sFullPath & ".xml"

    Set qdf = Nothing
    Set db = Nothing
End Sub

Hope This Helps, PH.
FAQ219-2884: How Do I Get Great Answers To my Tek-Tips Questions?
FAQ181-2886: How can I maximize my chances of getting an answer?

Triacona (TechnicalUser)
6 Mar 12 10:43
Dear PHV and Taaner,

Thanks for all the help bigsmile!

@PHV I have implemented your solution, thank you so so much!2thumbsup. Have a star!
I have no more errors or prompts for the TRADEAS.

The only bug left is, the XML file output is 1kb and has none of the records in the xml file, it just has the date and time it was created...

I run the query and in the criteria of TRADEAS it has:

CODE

Like '*  *'
So somehow the calling of the combo box value is not working...

I have tried a few different approaches...
It doesn't seem to work...

Any further help will be most appreciated, I am a bit of a newbie at using SQL in code, should I be calling it differently?

Thank you for your forthcoming help :)
 

Thank you,

Kind regards

Triacona

Triacona (TechnicalUser)
6 Mar 12 11:02
Dear PHV,
Sorry I didn't see the spacing in the SQL (that make a difference?? why?)...

CODE

Like '*" & Forms!MainScreen!SubFrmInput.Form!cmbCpTradeAs & "*'
I had spaces with '* " and " *' now corrected.

And it is inputing the correct data from the form...

The only problem is it does not export that data to the xml file...
I run the query and the data is all there.

I check the xml file and it has on the Date and time it was created, no records...

Below is the xml file output if opened in Notepad.

CODE

<?xml version="1.0" encoding="UTF-8"?>
<dataroot xmlns:od="urn:schemas-microsoft-com:officedata" generated="2012-03-06T15:51:57"/>

Is there anything else to configure within the Application.ExportXML command.

Thank you again for all of your help and forthcoming help2thumbsup
 

Thank you,

Kind regards

Triacona

Triacona (TechnicalUser)
7 Mar 12 11:06
Dear all,
I have changed the Xml output code slightly...

There is 1 positive...it now displayes the fields as headers in the XML file.

BUT it still does not display the data within those fields!!

DOH!!

I have no idea what to do now, I have read the MS helpfile and implemented the suggested changes in my output to code but no data...

Please see my code below..


CODE

Private Sub CpOutputQueryToXML_Click()
'*COMMERCIAL PREMISES CP OUTPUT TO XML BUTTON

    Dim db As DAO.Database
    Dim qdf As DAO.QueryDef
    Dim SQL As String
    Dim stDocName As String
        stDocName = ListCP.Column(2)
    Dim sFullPath As String
        sFullPath = txtPath & stDocName
    Dim sXmlInfo As String
        sXmlInfo = txtPath & "XmlInfo"
      
    Set db = CurrentDb
    Set qdf = db.QueryDefs(stDocName)

SQL = "SELECT SotQ5.REFVAL, SotQ5.TRADEAS, SotQ5.Con, SotQ5.CONTACT, SotQ5.UPRN, SotQ5.Add, " & _
        "SotQ5.POSTCODE, SotQ5.InspTyp, SotQ5.SCORE, SotQ5.TARGET_DATE, SotQ5.MainUse, SotQ5.MainUseDsc, " & _
        "SotQ5.SotUseDsc, SotQ5.Band, SotQ5.CPCONTTYPE, SotQ5.CONTADD, SotQ5.ACTUAL_DATE, SotQ5.QScore AS Q5, " & _
        "SotQ6.QScore AS Q6, SotQ7.QScore AS Q7, SotRating.TotalBcScore, SotRating.Rating, " & _
        "SotRating.LaemsUse AS businesstype, SotQ5.AddLine, AddressOnly(SotQ5.ADDRESS) AS AddO " & _
        "FROM SotRating " & _
        "INNER JOIN ((SotQ5 INNER JOIN SotQ6 ON SotQ5.REFVAL = SotQ6.REFVAL) " & _
        "INNER JOIN SotQ7 ON SotQ6.REFVAL = SotQ7.REFVAL) ON SotRating.REFVAL = SotQ5.REFVAL " & _
        "WHERE (((SotQ5.TRADEAS) Like '*" & Forms!MainScreen!SubFrmInput.Form!cmbCpTradeAs & "*')) " & _
        "ORDER BY SotQ5.TRADEAS"

        Debug.Print SQL
        qdf.SQL = SQL
        db.QueryDefs.Refresh
        
        Application.ExportXML acExportQuery, stDocName, sFullPath & ".xml", sXmlInfo, txtPath & "XmlData", , acUTF16

    qdf.Close
        
    Set qdf = Nothing
    Set db = Nothing
    

End Sub

Please help, this is driving me up the wall...
Thank you 2thumbsup

Thank you,

Kind regards

Triacona

Triacona (TechnicalUser)
15 Mar 12 8:34
Any thoughts anyone?smile
Thanks!

Thank you,

Kind regards

Triacona

Triacona (TechnicalUser)
16 Mar 12 12:10
Any thoughts?

Thank you,

Kind regards

Triacona

Triacona (TechnicalUser)
3 Apr 12 11:56
Help...!smile

Thank you,

Kind regards

Triacona

Triacona (TechnicalUser)
12 Apr 12 7:19
Please is there anyone who can help further???
Thank you! smile

Thank you,

Kind regards

Triacona

Triacona (TechnicalUser)
13 Apr 12 6:17
Hi,
I exported the data to Excel, then tried to save it as am XML file.
This did not work...
I then used Data->Xml->Xml source.
I then clicked on XML maps...and choose the XML file I outputed with the XML button in I created in Access.
This then gave me the headings, I then choose each heading respectively and choose the xml data heading by double clicking.
This then enabled me to save as XML with all data...
I am wondering if that is what is needed in Access...
I have the headings, all I need now is to string in the data...

Please help I am really stuck on thisbanghead
Thanks smile

 

Thank you,

Kind regards

Triacona

Triacona (TechnicalUser)
2 May 12 11:30
Please is there anyone who can help further???
Thank you!smile

Thank you,

Kind regards

Triacona

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close