Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 8th, 2004, 05:28 PM
Registered User
 
Join Date: Aug 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default MSXML2.XMLHTTP40. OnReadyStateChange won't work

I'm trying to use the MSXML.XMLHTTP object in Access VBA to upload and down load data from a web site. I found this code on Microsoft's MSDN site but it will not work.

The idea is to POST data to an asp/aspx page and receive data back. It WILL work SYNCHRONOUSLY but NOT ASYNCHRONOUSLY which is what I need. (Actually it works asynchronously if you poll the ReadyState property but I want to use the event/callback function. )

To use it asynchronously you define a function (onReadyStateChange) to fire off when the state changes. The problem is the onReadyStateChange function never gets called.

The example code (below) creates a class object 'MyReadyStateHandler' with only one method (SUB) 'OnReadyStateChange' (lines 8-11). An instance of this class is then assigned to the property 'OnReadyStateChange' of my XMLHTTP object 'XMLHttpRequest'. (line 5)

The 'true' argument on line 6 sets the method to 'asynchronous'.

I've tried this in VB 6, in Access 2002 and now in Access 2003 and it won't work. Does anybody have any idea why?

(I've been all over the Microsoft web site and can't find anything other than the sample code. I've found two references to the XMLHTTP object on this forum but they didn't address this issue.)

Thanks,
Larry

Here is the code:

     ' create the XMLHTTP object
1 Dim XMLHttpRequest As MSXML2.XMLHTTP40
2 Set XMLHttpRequest = New MSXML2.XMLHTTP40

     ' Create an instance of the wrapper class.
3 Dim MyOnReadyStateWrapper As MyReadyStateHandler
4 Set MyOnReadyStateWrapper = New MyReadyStateHandler

    ' Assign the wrapper class object to onreadystatechange.
5 XMLHttpRequest.OnReadyStateChange = MyOnReadyStateWrapper

    ' Get some stuff asynchronously.
6 XMLHttpRequest.open "POST", "http://localhost/test.xml", True
7 XMLHttpRequest.send

Add a Class Module and name it "MyReadyStateHandler"
Paste the following code into the class module:

   Sub OnReadyStateChange()
8 Debug.Print Form1.XMLHttpRequest.readyState
       ' whenever readyState changes onReadyStateChange is called
       ' readyState = 1 while waiting for the async call to return
9 If Form1.XMLHttpRequest.readyState = 4 Then
10 MsgBox "Done"
11 End If
   End Sub





Similar Threads
Thread Thread Starter Forum Replies Last Post
Mozilla onreadystatechange incompatibility cantaberry Ajax 3 August 21st, 2007 02:04 AM
MSXML2.XMLHTTP Caching? spraguey Classic ASP XML 2 September 19th, 2006 01:02 PM
MSXML2 Type mismatch desperado1306 Excel VBA 0 June 2nd, 2006 12:18 PM
MSXML2.ServerXMLHTTP help appreciated!! Steven1984 Classic ASP Professional 0 June 4th, 2005 12:49 PM
MSXML2.XMLHTTP Caching? spraguey Javascript 2 December 6th, 2004 09:20 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.