views:

28

answers:

1

Hi, guys.

For some reason I'm trying to parse this website: http://www.vblandrecords.com/index.aspx. I am currently trying to click Document type tab and then change From date value.

I supposed I could have done it with the following code, in VBA:

Option Explicit
Public WithEvents ieObj As InternetExplorer

Public Sub Launch()

    Set ieObj = CreateObject("InternetExplorer.Application")
    ieObj.Visible = True
    ieObj.navigate ("http://www.vblandrecords.com/index.aspx")

    While ieObj.readyState <> READYSTATE_COMPLETE

    Wend

    Dim TmpDOMObj, Frame As Object

    Set TmpDOMObj = ieObj.document.getElementById("tbMaintd3")

    TmpDOMObj.Click

    Set Frame = ieObj.document.getElementById("tbMain_frame3")
    Set TmpDOMObj = Frame.contentWindow.document.getElementById("txtStart")

    TmpDOMObj.Value = "10/1/2010"    

End Sub

But, I got a run-time error 91 - object variable not set.

I've done some research and it appeared that tree structure under tbMain_frame3 is formed up only after I click tbMaind3 tab, and I see it in MSIE developer tools, but I don't see it in my script.

I thought it was related to iFrame security issues I've read about, but staying on first tab and processing tbMain_frame0 works entirely fine.

Can anyone give me a hint about what's going on and how to handle this page?

Thanks.

+1  A: 

It may not be the best idea, but you could wait for the error to go away:

Dim test
On Error Resume Next

Do While True
    test = Frame.contentWindow.Document.getElementById("txtStart").Value
    If Err.Number = 0 Then
        Exit Do
    ElseIf Err.Number > 0 And Err.Number <> 91 Then
        Exit Sub
    End If

    Err.Clear
Loop
Remou
It's good enough for my simple job and it actually worked, thanks. Actual bad idea was to try to code something in 4 a.m. - I should have guessed this obvous solution myself. But thanks anyway. ;)
be here now