Results 1 to 4 of 4
  1. #1
    Stan Denman is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Mar 2012
    Posts
    55

    VBA Code to Open/Edit XML File

    I am very new to programming, so be gentle! I want to open and edit an xml file that will be the source of data for a pdf form. the data I want to use to edit the xml file is in MS Access. Trying to take this one step at a time, I am trying to open and edit an xml file via vba code. The following code throws a runtime error code 91. I don't understand why. I do have a reference to "Microsoft XML, v6.0"



    Private Sub Command0_Click()


    Dim xmlDoc As MSXML2.DOMDocument60
    Dim xmlNew As MSXML2.DOMDocument60


    xmlDoc.loadXML ("C:\users\stand\documents\contactlist.xml")


    End Sub

  2. #2
    Micron is online now Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,422
    The clue is in the message statement: Object variable or With block variable not set.
    When you declare an object variable, you must use the SET statement to tell Access to put that object in the memory space you've allocated with the Dim statement.
    Set xmlDoc = "C:\users\stand\documents\contactlist.xml"
    Then you can perform actions on it.
    Last edited by Micron; 05-01-2016 at 08:23 AM. Reason: grammar
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Stan Denman is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Mar 2012
    Posts
    55
    Thanks for your help. Now I get a type mismatch error with the Set statement.

  4. #4
    Micron is online now Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,422
    I know virtually nothing about the xml object model, so I'm afraid I won't be of much help beyond what I could do by Googling the subject, which I imagine you could do without me misguiding you. I will take one last stab though:
    Dim xmldoc As New DOMDocument60
    xmldoc.Load "C:\users\stand\documents\contactlist.xml"

Please reply to this thread with any new information or opinions.

Similar Threads

  1. VBA code to open a file with a dynamically changing filename
    By orangeman2003 in forum Programming
    Replies: 1
    Last Post: 09-09-2014, 06:17 PM
  2. Replies: 1
    Last Post: 05-31-2013, 08:53 AM
  3. Replies: 3
    Last Post: 02-22-2013, 06:41 AM
  4. Replies: 2
    Last Post: 12-21-2012, 04:59 PM
  5. Replies: 1
    Last Post: 06-29-2011, 07:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums