• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1337
  • Last Modified:

Object variable or With block variable not set

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
John Account
Asked:
John Account
  • 10
  • 5
  • 4
  • +3
5 Solutions
 
Harisha M GCommented:
Hi JohnLucio,
    Where are you getting the error ? (On which line ?)

Bye
---
Harish
0
 
John AccountAuthor Commented:
This line: TheSource = WebBrowser1.Document.body.outerText
0
 
Harisha M GCommented:
Try

Set TheSource = WebBrowser1.Document.body.outerText
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
John AccountAuthor Commented:
Thanks, mgh_mgharish, but that rendered me the following error: mgh_mgharish
0
 
Harisha M GCommented:
What !!!
0
 
John AccountAuthor Commented:
Ooops...rendered the following error: Object Required.
ROTFLMAO...sorry bout that.
0
 
edwardiiiCommented:
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
 
John AccountAuthor Commented:
Both of the .php pages, edwardiii.
0
 
edwardiiiCommented:
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
 
John AccountAuthor Commented:
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
 
BurbbleCommented:
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
 
JesterTooCommented:
Do you have something like

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

somewhere earlier in your code?
0
 
PePiCommented:
Jester is right. WebBrowser1 should have to be declared and set
0
 
BurbbleCommented:
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
 
edwardiiiCommented:
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
 
John AccountAuthor Commented:
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
 
John AccountAuthor Commented:
WebBrowser control is embedded on my form, and the WebBrowser control name is WebBrowser1, as it's being called in the code.
0
 
edwardiiiCommented:
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
 
BurbbleCommented:
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
 
John AccountAuthor Commented:
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
 
John AccountAuthor Commented:
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
 
BurbbleCommented:
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
 
John AccountAuthor Commented:
Thanks, Burbble--you're a great man! That safeguard really comes in handy!
0
 
BurbbleCommented:
Glad to help :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

  • 10
  • 5
  • 4
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now