Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

With block or variable not set error?

Status
Not open for further replies.

patriciaxxx

Programmer
Jan 30, 2012
277
GB
I have the following sub, which should connect to ebay and output the following in the Immediate Window
US $2.55
No Data
US $6.50

But when I run it all I get is error With block or variable not set. I’m using winXP, Access 2003. I have no special references set and the code compiles successfully. I have checked the help and internet for the error but can’t seem to work out the problem.

Code:
[COLOR=#204A87]Option Compare Database
Option Explicit

Sub xmlHttp()

    Dim x As Integer
    Dim URl As String
    Dim objShipping As Object
    Dim divShip As Object

    Dim xmlHttp As Object
    Set xmlHttp = CreateObject("MSXML2.ServerXMLHTTP.6.0")

    Dim ITEM_NUMBER_ARRAY As Variant
    ITEM_NUMBER_ARRAY = Array("290941626676", "130942854921", "400035340501")
    For x = 0 To UBound(ITEM_NUMBER_ARRAY)

        ''Here is your URL
        URl = "[URL unfurl="true"]http://www.ebay.com/itm/"[/URL] & ITEM_NUMBER_ARRAY(x) & "?ru=http%3A%2F%2F[URL unfurl="true"]www.ebay.com%2Fsch%2Fi.html%3F_from%3DR40%26_sacat%3D0%26_nkw%3D"[/URL] & ITEM_NUMBER_ARRAY(x) & "%26_rdc%3D1"

        xmlHttp.Open "GET", URl, False
        xmlHttp.setRequestHeader "Content-Type", "text/xml"
        xmlHttp.send


        Dim html As Object
        Set html = CreateObject("htmlfile")

        html.body.innerHTML = xmlHttp.ResponseText
        Set objShipping = html.getelementbyid("shippingSection").getElementsbytagname("td")(0)


        If Not objShipping Is Nothing Then
            Set divShip = objShipping.ChildNodes(1)
            Debug.Print divShip.innerHTML
            Else
            Debug.Print "No Data"
        End If

    Next
End Sub[/color]
 
Which line of code raises the error ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi PHV

Thanks for replying.

I’ve highlighted the line in yellow.

Code:
[COLOR=#204A87]Option Compare Database
Option Explicit

Sub xmlHttp()

    Dim x As Integer
    Dim URl As String
    Dim objShipping As Object
    Dim divShip As Object

    Dim xmlHttp As Object
    Set xmlHttp = CreateObject("MSXML2.ServerXMLHTTP.6.0")

    Dim ITEM_NUMBER_ARRAY As Variant
    ITEM_NUMBER_ARRAY = Array("290941626676", "130942854921", "400035340501")
    For x = 0 To UBound(ITEM_NUMBER_ARRAY)

        ''Here is your URL
        URl = "[URL unfurl="true"]http://www.ebay.com/itm/"[/URL] & ITEM_NUMBER_ARRAY(x) & "?ru=http%3A%2F%2F[URL unfurl="true"]www.ebay.com%2Fsch%2Fi.html%3F_from%3DR40%26_sacat%3D0%26_nkw%3D"[/URL] & ITEM_NUMBER_ARRAY(x) & "%26_rdc%3D1"

        xmlHttp.Open "GET", URl, False
        xmlHttp.setRequestHeader "Content-Type", "text/xml"
        xmlHttp.send


        Dim html As Object
        Set html = CreateObject("htmlfile")

        html.body.innerHTML = xmlHttp.ResponseText
        [highlight #FCE94F]Set objShipping = html.getelementbyid("shippingSection").getElementsbytagname("td")(0)[/highlight]

        If Not objShipping Is Nothing Then
            Set divShip = objShipping.ChildNodes(1)
            Debug.Print divShip.innerHTML
            Else
            Debug.Print "No Data"
        End If

    Next
End Sub[/color]
 
Are you sure the item numbers are still valid ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi PHV

Well, I feel somewhat silly; I never would have guessed that.

I tried it with current item numbers and it worked. So yes, you are right, thank you for your help.

I’m going to play around with it now that it’s working and see if I can get it to do some more useful things.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top