Object required after transfering code from form to module

Notedop

Registered User.
Local time
Today, 17:08
Joined
Jul 5, 2012
Messages
19
I've created some code to connect sent a XML request and receive it back again. For testing purposes I created it under Private sub command button.
When I got it working, I created a function of the code a copied it into a module. However now I'm getting an Object Required error on line
(I can not post the link as this forum does not allow it because this is my first post. It should be between the ""
https
://
www
ups.com/ups.app/xml/Track )

Code:
oXMLHttp.Open "POST", "", False

The only thing that change in comparisation with the code on the form is where itgets the tracking number from and that it returns the status value.

The following is the full code:

Code:
Public Function Get_tracking_info(Trackingid As String) As String
 
Dim oXMLHttp As XMLHTTP
Dim Requeststring
Dim accesstring
Dim XDoc As MSXML2.DOMDocument
Dim i As Integer
Dim objnodelist As MSXML2.IXMLDOMNodeList
Dim error As Boolean
Dim errormsg As String
Dim status As String
Dim bla As Variant
Set oXMLHttp = New XMLHTTP
Set dom = New DOMDocument
accesstring = "<?xml version=1.0 ?>" & _
" <AccessRequest xml:lang='en-US'>" & _
"<AccessLicenseNumber>" & _
DLookup("accesscode", "credentials") & "</AccessLicenseNumber>" & _
"<UserId>" & _
DLookup("username", "credentials") & _
"</UserId>" & _
"<Password>" & _
DLookup("password", "credentials") & _
"</Password>" & _
"</AccessRequest>"
Requeststring = "<?xml version=1.0 ?>" & _
"<TrackRequest><IncludeFreight>01</IncludeFreight>" & _
"<Request>" & _
"<TransactionReference>" & _
"<CustomerContext>Open POD</CustomerContext>" & _
"</TransactionReference>" & _
"<RequestAction>Track</RequestAction>" & _
"</Request><shipmenttype><code>02</code></shipmenttype>" & _
"<ShipmentIdentificationNumber>" & Trackingid & "</ShipmentIdentificationNumber>" & _
"</TrackRequest>"
Requeststring = accesstring & Requeststring
sendrequest.Value = Requeststring
' prepare the HTTP POST request
oXMLHttp.Open "POST", "", False
oXMLHttp.setRequestHeader "Content-Type", _
"application/x-www-form-urlencoded"
' send the request
oXMLHttp.send Requeststring
oXMLHttp.getAllResponseHeaders
'MsgBox oXMLHttp.responseText
output.Value = oXMLHttp.responseText
 
 
Set XDoc = New MSXML2.DOMDocument
XDoc.async = False
XDoc.validateOnParse = False
XDoc.loadXML (oXMLHttp.responseText)
 
error = False
 
Set objnodelist = XDoc.selectNodes("//*")
For i = 0 To (objnodelist.length - 1)
 
  Set objnode = objnodelist.nextNode
 
  Select Case objnode.baseName
    Case "ResponseStatusCode"
        If objnode.Text = "0" Then error = True
    Case "ErrorDescription"
        If error = True Then
            MsgBox objnode.Text, vbCritical, "Error message"
            status = "error" & objnode.Text
            Exit For
        End If
    Case "CurrentStatus"
        'jump to second childnode in collection.
        Set objnode = objnodelist.nextNode
        i = i + 1
        Set objnode = objnodelist.nextNode
        i = i + 1
        status = objnode.Text
    End Select
 
  'If objnode.baseName = "ResponseStatusCode" Then
  'MsgBox objnode.baseName & ": " & objnode.Text
  'End If
Next
 
Get_tracking_info = status
 
End Function
 
Hi, welcome to AWF.

Can you confirm that you're getting a compile error or a runtime error - and which line it's pointing to? The Open method or some reference to a URL that you were making?

I notice in your code that you end up with a
output.Value = oXMLHttp.responseTextwithout declaring an output object. Was it an object on your form?

Cheers
 
I notice in your code that you end up with a
output.Value = oXMLHttp.responseTextwithout declaring an output object. Was it an object on your form?

This was the issue, I outputted the xmltext for debugging purposes.

Thanks for the heads up!
 
No worries. Little things are easy to miss.
 

Users who are viewing this thread

Back
Top Bottom