?
Solved

Object variable or With block variable not set

Posted on 2005-05-11
24
Medium Priority
?
1,193 Views
Last Modified: 2008-01-09
I'm getting error: Object variable or With block variable not set
Hello Experts. My code is below. Please let me know what am I missing. Thanks in advance!

Option Explicit
Dim TheSource As String

Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
TheSource = WebBrowser1.Document.body.outerText
Select Case WebBrowser1.LocationURL
        Case "http://www.MyURL.com/MyValues.php"
            ListValues
            Exit Sub
        Case "http://www.MyURL.com/EnVersion.txt"
            txtUpdate.Text = TheSource
            Chk4Update
            Exit Sub
        Case "http://www.MyURL.com/picquery.php"
            btePicCount = "0"
            Do While WebBrowser1.ReadyState < 4
            DoEvents
            Loop

                btePicCount = Split(TheSource, ",")(0)

            If btePicCount = 1 Then 'If no picture in profile then prompt user to take a picture
                Dim frm As New frmStartCamMsg
                Set frm = New frmStartCamMsg
                frm.imgHelp.Visible = False
                frm.Label1.Caption = "Add A Photo To Your Profile?"
                frm.Caption = "Take a picture of yourself now!"
                frm.lblNote.Caption = "You do not have a photo of yourself on your profile. To take a picture now, click YES to start Web Cam, then select Photo from the menu bar therein. (a web cam is required, of course!)"
                frm.Show
            End If
           
                    Search4PicName
        Exit Sub
        Case "http://www.MyURL.com/user.php?IP=" & RemoteCon
        ListHisValues
End Select
End Sub
0
Comment
Question by:John Account
  • 10
  • 5
  • 4
  • +3
24 Comments
 
LVL 37

Expert Comment

by:Harisha M G
ID: 13981360
Hi JohnLucio,
    Where are you getting the error ? (On which line ?)

Bye
---
Harish
0
 

Author Comment

by:John Account
ID: 13981389
This line: TheSource = WebBrowser1.Document.body.outerText
0
 
LVL 37

Assisted Solution

by:Harisha M G
Harisha M G earned 400 total points
ID: 13981466
Try

Set TheSource = WebBrowser1.Document.body.outerText
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:John Account
ID: 13981494
Thanks, mgh_mgharish, but that rendered me the following error: mgh_mgharish
0
 
LVL 37

Expert Comment

by:Harisha M G
ID: 13981524
What !!!
0
 

Author Comment

by:John Account
ID: 13981560
Ooops...rendered the following error: Object Required.
ROTFLMAO...sorry bout that.
0
 
LVL 10

Expert Comment

by:edwardiii
ID: 13981624
That was funny:)  By the way, which URL are you navigating to (e.g. which Select Case URL applies when you get the error)?
0
 

Author Comment

by:John Account
ID: 13981654
Both of the .php pages, edwardiii.
0
 
LVL 10

Accepted Solution

by:
edwardiii earned 400 total points
ID: 13981758
Hmmm.  I see three.  Let's erase everything but the first URL, as below.  Do you still get the Object error?  What is the code in "ListValues"?

     TheSource = WebBrowser1.Document.body.outerText
     Select Case WebBrowser1.LocationURL
        Case "http://www.MyURL.com/MyValues.php"
            ListValues
            Exit Sub
0
 

Author Comment

by:John Account
ID: 13981805
Edwardiii...I think we're looking in the wrong area. See, if I remove everything except "Set TheSource = WebBrowser1.Document.body.outerText", I still get the same error: Object required. Hence, I need to instantiate an object or something to that effect, and don't know what. But I think it has something to do with the browser object.
0
 
LVL 7

Expert Comment

by:Burbble
ID: 13981830
I have loaded .PHP pages as you describe, and am unable to recreate the error...

Windows ME / IE 5.5 SP2

Could it be an Internet Explorer issue on your system?
0
 
LVL 22

Assisted Solution

by:JesterToo
JesterToo earned 400 total points
ID: 13981853
Do you have something like

   Dim WebBrowser1
   Set WebBrowser1 = CreateObject("InternetExplorer.Application")

somewhere earlier in your code?
0
 
LVL 6

Assisted Solution

by:PePi
PePi earned 400 total points
ID: 13981878
Jester is right. WebBrowser1 should have to be declared and set
0
 
LVL 7

Assisted Solution

by:Burbble
Burbble earned 400 total points
ID: 13981969
I made the assumption that he was using a WebBrowser control placed on a form? Under this circumstance, the code works fine for me.

Do you have the latest Visual Studio Service Pack installed?

http://msdn.microsoft.com/vstudio/downloads/updates/sp/vs6/sp6/default.aspx
0
 
LVL 10

Expert Comment

by:edwardiii
ID: 13982024
JohnLucio--do you have a WebBrowser control embedded in your userform?  How (and where from) are you doing "WebBrower1.Navigate..."?  What's the name of your WebBrowser control?
0
 

Author Comment

by:John Account
ID: 13982107
Hmmmnnn...I don't know, Burbble--with all the Spyware/Addware around, maybe my internet explorer has been damaged.

JesterToo, I tried that, but get the following error: "Run-time error '-2147467259 (80004005)':
Method 'Document' of object 'IWebBrowser2' failed" -- and I have no idea what a IWebBrowser2 is! Interestingly enough, I don't get this error when "Set" is added to this line: TheSource = WebBrowser1.Document.body.outerText

Burbble, the web browser control is placed on the form. And, Yes, I have the Service Pack installed.
0
 

Author Comment

by:John Account
ID: 13982114
WebBrowser control is embedded on my form, and the WebBrowser control name is WebBrowser1, as it's being called in the code.
0
 
LVL 10

Expert Comment

by:edwardiii
ID: 13982303
That's good news.  Now--how are you navigating to the URL?  Please paste your exact code, including the Private Sub item the code is in.  For example, this is how it might look:

     Private Sub Command1_Click()
         WebBrowser1.Navigate ("http://www.MyURL.com/MyValues.php")
    End Sub
0
 
LVL 7

Expert Comment

by:Burbble
ID: 13982350
What version of IE do you have?

"Set" is not necessary on the line, because all it is doing is assigning a string to a String variable.
0
 

Author Comment

by:John Account
ID: 13982937
JesterToo, what should I dim WebBrowser1 as?--WebBrowser??--like this:
Dim WebBrowser1 As WebBrowser  -- If so, it gives me a Type Mismatch error!

edwardiii, the URLs are being called like this:
WebBrowser1.Navigate ("http://www.MyURL.com/MyValues.php")
WebBrowser1.Navigate ("http://www.MyURL.com/EnVersion.txt")
WebBrowser1.Navigate ("http://www.MyURL.com/picquery.php")

Burbble, thanks for informing me about the Set. I thought that was kinda fishy, putting it there in the first place! I'm using version 6 or IE.

This whole thing is mind-boggling!  Sure do appreciate your thoughts, and hope one of you can help soon.
0
 

Author Comment

by:John Account
ID: 13983092
ah ha--I figured it out! Guys, what happened here was that, since the browser control hadn't accessed a web site yet, it renders the error message below; hence, my WebBrowser1_DocumentComplete routine didn't know what to do in that instance. (So, to fix the problem, I simply made sure that WebBrowser1 goes to http://www.MyURL.com/EnVersion.txt for update confirmation before doing anything else) Many thanks to you all for trying to help me figure this out; I'll divide the points equally amoung you.

The page cannot be displayed
The page you are looking for is currently unavailable. The Web site might be experiencing technical difficulties, or you may need to adjust your browser settings.

Please try the following:
Click the  Refresh button, or try again later.

If you typed the page address in the Address bar, make sure that it is spelled correctly.

To check your connection settings, click the Tools menu, and then click Internet Options. On the Connections tab, click Settings. The settings should match those provided by your local area network (LAN) administrator or Internet service provider (ISP).
If your Network Administrator has enabled it, Microsoft Windows can examine your network and automatically discover network connection settings.
If you would like Windows to try and discover them,
click  Detect Network Settings
Some sites require 128-bit connection security. Click the Help menu and then click About Internet Explorer to determine what strength security you have installed.
If you are trying to reach a secure site, make sure your Security settings can support it. Click the Tools menu, and then click Internet Options. On the Advanced tab, scroll to the Security section and check settings for SSL 2.0, SSL 3.0, TLS 1.0, PCT 1.0.
Click the  Back button to try another link.

Cannot find server or DNS Error
Internet Explorer
0
 
LVL 7

Expert Comment

by:Burbble
ID: 13983108
Ohh ok, so the WebBrowser1_DocumentComplete event was firing before it actually nativigated to a page?

As a safeguard, you might consider adding a line like:

    If Len(WebBrowser1.LocationURL) = 0 Then Exit Sub

to the WebBrowser1_DocumentComplete sub.
0
 

Author Comment

by:John Account
ID: 13983333
Thanks, Burbble--you're a great man! That safeguard really comes in handy!
0
 
LVL 7

Expert Comment

by:Burbble
ID: 13991180
Glad to help :)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month15 days, 6 hours left to enroll

839 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