Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 8th, 2004, 05:28 PM
Registered User
 
Join Date: Aug 2004
Location: , , .
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 03:13 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.