Solved

AsyncRead and a Form with ActiveX

Posted on 1998-05-04
10
256 Views
Last Modified: 2008-02-01
I have a simply UserControl the calls AsyncRead(?,?,?) and downloads a text file from a web server and it works fine.

I then have the UserControl open a Form with

Form1.Show vbModal

And a form is displayed.  I then have a button on the form that does the following...

Private Sub Command1_Click()
   On Error Goto ErrorHandler  

   AsyncRead "http://whatver.com/text.txt, AsyncType, "NameHere"
   ' Or UserControl1.AsyncRead "http://whatver/text.txt, AsyncType, "NameHere"

ErrorHandler:
   MsgBox("Error in AsyncRead")
End Sub

But this will never start the download of the text.txt file.  
I can only get the text file to download when the AsyncRead is called from a Sub within the UserControl.  As soon as call AsyncRead from the form, it always jumps to ErrorHandler.

Anyone?  How can I call AsyncRead from a vbModal form???

Thanks.  I'm hoping to get an example.
0
Comment
Question by:scottg
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 2

Expert Comment

by:marti
ID: 1439069
Do you have a public method 'AsyncRead' for your UserControl declared? Does the parameters of that method match the ones you are passing?
0
 

Author Comment

by:scottg
ID: 1439070
No, its not offically declared, but its automatically available, and works fine from the UserControl, but not from a form.  

Example:

Private Sub UserControl_Click()
   On Error GoTo ErrorTrap
   AsyncRead "http://site/text.txt", vbAsyncTypeFile, "test"
   GoTo Complete

ErrorTrap:
   MsgBox ("Error with Asyncread")

Complete:
   MsgBox ("Asyncread probably worked")
End Sub

This works fine, because asyncread called from a SUB within the usercontrol.  But if it opens a form instead...

Private Sub UserControl_Click()
   Form1.Show vbModal
End Sub

and has the form with a button that does the above AsyncRead;
will not work and always jumps to the error.

Any idea?  I'll forward you some cash if you can figure it out.

Thanks.

0
 
LVL 1

Expert Comment

by:lbk
ID: 1439071
In you error handler use

ErrHandler:
  MsgBox Err.Description
end sub

and tell me what the error message is.
AsynchRead might try to display another form, and that's not allowed when a modal form is showing.
0
 
LVL 2

Expert Comment

by:marti
ID: 1439072
Scott,
Declare a public method of your UserControl say StartLoading. Put your code
    AsyncRead "http://site/text.txt", vbAsyncTypeFile, "test"
in that method.
On Command1_Click event of the command button type:
    UserControl11.StartLoading
to call that method.
And that's it. If you have problems I'll send you a sample.
0
 

Author Comment

by:scottg
ID: 1439073
On Error GoTo ErrorTrap
UserControl1.AsyncRead "http://site/text.txt", vbAsyncTypeFile, "Name"
Goto Compelete:

ErrorTrap:
   MsgBox Err.Description
   
Complete:
   MsgBox ("Asyncread probably worked")
   
If the above is called from a command butotn on the modal form , it reports "Object Required".  I don't think I'm properly referencing AsyncRead within the UserControl.   Or AsyncRead isn't available to the form for some reason.  Is there something I should have Declared?  


marti:
>If you have problems I'll send you a sample.

If you actually have a small example that would be great.  My address is scottg@niagara.com.  I tried what you mentioned before, and kept getting "Runtime Error 424, Object Required".  I don't think I was doing it properly.  If you could, possibly E-Mail anything you have?  Thanks.

Scott.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Expert Comment

by:lbk
ID: 1439074
Can you run this project within VB, or only in EXE format?

If you can, set Error trapping to Always Break on errors. It will then stop right at this line. When it does, highlight UserControl1 and hit <shift><F9>. If the dialogue shows <NOTHING> under value, the usercontrol you are referencing does not exist. Otherwise, add the control-project (File>Add Project> and make sure that you have error trapping set to Always Break in that project as well. It should then stop as close to the error as possible, and you can see what the variable is you didn't set, or whatever else causes the trouble
0
 

Author Comment

by:scottg
ID: 1439075
I got it working now with marti's example.  I had to mount a separate usercontrol onto the modal form and reference that one, not the UserControl1 directly.  This is probably obvious to you, but I'm too inexperienced to see that yet.

Thank for your help though.  
0
 
LVL 3

Expert Comment

by:fguerreiro_inix
ID: 1439076
Hello SCOTTG

AsyncRead only works with user controls. if you use
(AsyncRead "http://site/text.txt", vbAsyncTypeFile, "test" )
on click of a button on a form a error ocurs because
the current object is the form (and the form doesn't have that method). You  must use (UserControlName.AsyncRead "http://site/text.txt", vbAsyncTypeFile, "test" )

Hope this helps


0
 
LVL 2

Expert Comment

by:marti
ID: 1439077
Scott, I can not post an answer. I have to reject the fguerreiro_inix's answer first.
0
 
LVL 2

Accepted Solution

by:
marti earned 200 total points
ID: 1439078
See above.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now