locked
Access 2013: Using a Button on Form to open and download an XML file. How to write the Visual Basic programming code for doing it? RRS feed

  • Question

  • Hi all,

    I am new in doing Access 2013 and Visual Basic programming.  I learned a little bit of Visual Basic 6.0 long time ago. I used Access 2007 to download an XML file directly to Access 2007 before.  Now, I am learning how to download an XML file by clicking a Button that has the Visual Basic (or VBA) codes to open and download the XML file.  I have created a Button that has the following:

    Private Sub Command8_Click()

    End Sub

    I have my XML file stored in a folder of my C:// drive.

    Please kindly help and instruct me what Visual Basic (or VBA) codes I need to put into the Private Sub Command8_Click() place to do the "open" and "download" my XML file to my Access 2013.

    Thanks in advance,

    Scott Chang

    P. S. I want to download the XML file into a Table of Access 2013.
    Tuesday, December 1, 2015 7:37 PM

Answers

  • Hi Scott. Looks like you may have an extra comma after Application.ImportXML. Try removing it and see if that helps. Or try simply:

    Application.ImportXML "c:\xml files-Microsoft samples\books.xml"

    Hope that helps...

    • Edited by .theDBguy Wednesday, December 2, 2015 4:04 PM
    • Marked as answer by Scott H Chang Wednesday, December 2, 2015 7:06 PM
    Wednesday, December 2, 2015 4:02 PM
  • Hi Scott,

    I don't think there's an equivalent macro action to import an XML file into a table. If you *must* use a macro for all your other code, then the next best thing I could think of is to encapsulate the above code in a Public Function and then call that function in your macro. In a sense, you can't get away from using VBA for this.

    Good luck!

    • Marked as answer by Scott H Chang Thursday, December 3, 2015 12:58 PM
    Wednesday, December 2, 2015 8:05 PM

All replies

  • Hi,

    Check out the sample code here.

    Hope that helps...

    • Proposed as answer by André Santo Tuesday, December 1, 2015 7:49 PM
    Tuesday, December 1, 2015 7:47 PM
  • Hi Andre, Thanks for your response.

    I tried the following Code:

    Private Sub Command_Click()

    Application.ImportXML, _

    DataSource:="C:\XML Files-Microsoft Samples\books.xml", _

    ImportOption:=acStructureAndData

    End Sub

    I got the following Comple error:

    Microsoft Visual Basic for Application

    Compile error:  Expected expression

    I guess this Compile error is for the "DataSource:="C:\XML Files-Microsoft Samples\books.xml", _

    I don't know to how to correct this Compile error.  Please kindly help and tell me how to correct this Compile error.

    Thanks again,

    Scott Chang

    Wednesday, December 2, 2015 2:59 PM
  • Hi Scott. Looks like you may have an extra comma after Application.ImportXML. Try removing it and see if that helps. Or try simply:

    Application.ImportXML "c:\xml files-Microsoft samples\books.xml"

    Hope that helps...

    • Edited by .theDBguy Wednesday, December 2, 2015 4:04 PM
    • Marked as answer by Scott H Chang Wednesday, December 2, 2015 7:06 PM
    Wednesday, December 2, 2015 4:02 PM
  • Hi DB Guy, Thanks for your valuable response.

    I made correction on my coding and ran the revised code.  It worked nicely.

    One new thing to ask you: I want to use Macro (instead of Application.Import XML Method) to do the task of importing xml file. How can I program to do this new coding?

    Please kindly help and give me the guidance or detailed instructions for doing this new task.

    Many Thanks again,

    Scott Chang

    Wednesday, December 2, 2015 7:49 PM
  • Hi Scott,

    I don't think there's an equivalent macro action to import an XML file into a table. If you *must* use a macro for all your other code, then the next best thing I could think of is to encapsulate the above code in a Public Function and then call that function in your macro. In a sense, you can't get away from using VBA for this.

    Good luck!

    • Marked as answer by Scott H Chang Thursday, December 3, 2015 12:58 PM
    Wednesday, December 2, 2015 8:05 PM