title: VBA Access: XML, Error '91': Object variable or With block variable not set?
body: <p>Now that school is out for the summer and I have some free time I have chosen to create a personal book inventory system. While researching I came across this post by Jules: <a href="https://stackoverflow.com/questions/2454348/isbn-bookdata-lookup-to-fill-in-a-database">ISBN -&gt; bookdata Lookup to fill in a database</a></p>
  
  <p>When trying to implement my code below, I first got a <code>Run-time error: Access is denied</code> when using <code>Set xmlhttp = CreateObject("MSXML2.xmlhttp")</code>. I found a post (<a href="http://social.msdn.microsoft.com/Forums/en-US/1abda1ce-e23c-4d0e-bccd-a323aa7f2ea5/access-is-denied-while-using-microsoftxmlhttp-to-get-a-url-link-in-vbscript-help" rel="nofollow noreferrer">http://social.msdn.microsoft.com/Forums/en-US/1abda1ce-e23c-4d0e-bccd-a323aa7f2ea5/access-is-denied-while-using-microsoftxmlhttp-to-get-a-url-link-in-vbscript-help</a>) that said to change the line to <code>Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP.6.0")</code>.</p>
  
  <p>I now am receiving <code>Run-time error '91': Object variable or With block variable not set.</code> </p>
  
  <p>Anyone have any ideas on how to resolve this? I'm new to working with XML. For testing I am using the Immediate Window and typing <code>testlookup("0007102968")</code>.</p>
  
  <p>Module SearchISBN:</p>
  
  <pre><code>Option Compare Database
  Option Explicit
  
  Public Function testlookup(value As String)
      Dim book
      Set book = New isbn
      book.Lookup (value)
      Debug.Print book.Title
      Debug.Print book.PublisherText
  End Function
  </code></pre>
  
  <p>Class Module isbn:</p>
  
  <pre><code>Option Compare Database
  Option Explicit
  
  'https://stackoverflow.com/questions/2454348/isbn-bookdata-lookup-to-fill-in-a-database
  ' AccessKeys created with account on ISBNDB.com
  ' Reference in (Tools-&gt;Refernces) made to "Microsoft XML"
  
  Dim strTitle As String
  Dim strAuthor As String
  Dim strPublisher As String
  Dim strSummary As String
  Dim strPrice As Currency
  Dim strISBN10 As Integer
  Dim strISBN13 As Integer
  Dim strNotes As String
  'Dim strPersRating As String
  Dim accessKey As String
  
  Private Sub Class_Initialize()
      ' Set AccessKey value of ISBNDB API
      accessKey = "NSOY388Z"
  End Sub
  Property Get Title() As String
      Title = strTitle
  End Property
  Property Get Author() As String
      Author = strAuthor
  End Property
  Property Get Publisher() As String
      Publisher = strPublisher
  End Property
  Property Get Summary() As String
      Summary = strSummary
  End Property
  Property Get Price() As Currency
      Price = strPrice
  End Property
  Property Get ISBN10() As Integer
      ISBN10 = strISBN10
  End Property
  Property Get ISBN13() As Integer
      ISBN13 = strISBN13
  End Property
  Property Get Notes() As String
      Notes = strNotes
  End Property
  
  Public Function Lookup(isbn As String) As Boolean
      Lookup = False
  '    Dim xmlhttp
  '    Dim strTest As String
  '    strTest = "https://isbndb.com/api/books.xml?access_key=" &amp; accessKey &amp; "&amp;results=texts&amp;index1=isbn&amp;value1=" &amp; isbn
  '    Debug.Print strTest
  '    'Run-time error, access is denied
  '    ' Set xmlhttp = CreateObject("MSXML2.xmlhttp")
  '    Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP.6.0")
  '    xmlhttp.Open "Get", strTest, False '"https://isbndb.com/api/books.xml?access_key=" &amp; accessKey &amp; "&amp;results=texts&amp;index1=isbn&amp;value1=" &amp; isbn, False
  '    xmlhttp.send
  '    Debug.Print xmlhttp.responseText
  '    Debug.Print "Response: " &amp; xmlhttp.responseXML.XML '
  '    Dim xmldoc
  ''    Set xmldoc = CreateObject("Microsoft.XMLDOM")
  ''    xmldoc.loadXML (xmlhttp.responseXML.XML)
  ''    ERROR
  ''    If (xmldoc.selectSingleNode("//BookList").getAttribute("total_results") = 0) Then
  ''        MsgBox "Invalid ISBN or not in database"
  ''        Exit Function
  ''    End If
  ''    If (xmldoc.selectSingleNode("//BookList").getAttribute("total_results") &gt; 1) Then
  ''        MsgBox "Caution, got more than one result!"
  ''        Exit Function
  ''    End If
  '
  '    Set xmldoc = New DOMDocument
  '    xmldoc.loadXML (xmlhttp.responseText)
  '
  '
  '
  '    strTitle = xmldoc.selectSingleNode("//BookData/TitleLong").Text
  '    strAuthor = xmldoc.selectSingleNode("//BookData/AuthorsText").Text
  '    strPublisher = xmldoc.selectSingleNode("//BookData/PublisherText").Text
  '    strNotes = xmldoc.selectSingleNode("//BookData/Notes").Text
  '    strSummary = xmldoc.selectSingleNode("//BookData/Summary").Text
  '
  
      Dim xmlhttp As MSXML2.xmlhttp
      Dim xmldoc As MSXML2.DOMDocument
      Dim XMLNodes As MSXML2.IXMLDOMNodeList
      Dim xmlElement As MSXML2.IXMLDOMElement
      Dim bookTitle As String
      Dim myErr As MSXML2.IXMLDOMParseError
  
      Dim strTest As String
      strTest = "https://isbndb.com/api/books.xml?access_key=" &amp; accessKey &amp; "&amp;results=texts&amp;index1=isbn&amp;value1=" &amp; isbn
  
      ' Fetch the XML - THIS IS WHERE I AM NOW GETTING ERROR
      xmlhttp.Open "Get", strTest, False '"https://isbndb.com/api/books.xml?access_key=" &amp; accessKey &amp; "&amp;results=texts&amp;index1=isbn&amp;value1=" &amp; isbn, False
      xmlhttp.send
  
      Set xmldoc = New DOMDocument
      xmldoc.loadXML (xmlhttp.responseText)
  
      Set XMLNodes = xmldoc.getElementsByTagName("BookData")
  
      Dim i As Integer
  
      ' Get the data
      For i = 1 To XMLNodes.length
          Set xmlElement = XMLNodes.nextNode
          bookTitle = xmlElement.getElementsByTagName("Title").Item(0).nodeTypedValue
      Next
  
      Lookup = True
  
  End Function
  </code></pre>
  
  <p><strong>EDIT</strong>: Still getting the error, but am now getting a response in the immediate window:</p>
  
  <pre><code>https://isbndb.com/api/books.xml?access_key=NSOY388Z&amp;results=texts&amp;index1=isbn&amp;value1=0007102968
  Response: 
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;ISBNdb server_time="2013-06-20T16:20:00Z"&gt;
  &lt;BookList total_results="1" page_size="10" page_number="1" shown_results="1"&gt;
  &lt;BookData book_id="the_times_book_of_quotations" isbn="0007102968" isbn13="9780007102969"&gt;
  &lt;Title&gt;The Times book of quotations&lt;/Title&gt;
  &lt;TitleLong&gt;&lt;/TitleLong&gt;
  &lt;AuthorsText&gt;&lt;/AuthorsText&gt;
  &lt;PublisherText publisher_id="times_books"&gt;[Glasgow] : Times Books : 2000.&lt;/PublisherText&gt;
  &lt;Summary&gt;&lt;/Summary&gt;
  &lt;Notes&gt;Includes index.&lt;/Notes&gt;
  &lt;UrlsText&gt;&lt;/UrlsText&gt;
  &lt;AwardsText&gt;&lt;/AwardsText&gt;
  &lt;/BookData&gt;
  &lt;/BookList&gt;
  &lt;/ISBNdb&gt;
  </code></pre>
  
  <p>Browser results of https request:</p>
  
  <p><img src="https://i.stack.imgur.com/lKIaH.png" alt=""></p>