none
Insert value into web form field, that is in a frame RRS feed

  • Question

  • I have made references to the MSHTML library and MS Internet Controls setup, and I am trying to fill out a form using a variable. The main page consists of 3 frames, and the "top" frame is where my form is located. The code below will work, if I navigate to the frame directly, with the form in the frame being named "NavPage". and the "Cnum" being the name of the element i want to add a value to, then click a button to retrieve the number

    Dim HTMLDoc2 As MSHTML.HTMLDocument 
    Set HTMLDoc2 = Browser.document 
    HTMLDoc2.forms("NavPage").CNum.Value = "12345" 'will change this to become a variable 
    HTMLDoc2.forms("Navpage").GetCase.Click 

    Question is, how do I reference to the first top frame ("top" is the name) using DOM, because right now, it doesnt work, and it spits "Object variable or With block variable not set" at me.

    Im thinking something along the lines of

    HTMLDoc2.frames(??).forms("Navpage").GetCase.Click  ' Not sure about the syntax here

    Alternatively, since this code works if you navigate to the source page, is there a way i could pull the top frame source page in first, then the second and third frames following?



    • Edited by jayinthe813 Thursday, September 6, 2012 5:48 PM
    Thursday, September 6, 2012 3:24 PM

Answers

  • Try this - I think a frame is a separate document.

    Dim frmHTMLFrame As MSHTML.HTMLDocument

    Set HTMLDoc2 = Browser.Document
    Set frmHTMLFrame = HTMLDoc2.frames(0).Document

    Do Until frmHTMLFrame.ReadyState = "complete"
    DoEvents
    Loop

    frmHTMLFrame.forms("NavPage").CNum.Value = "12345"

    frmHTMLFrame.forms("Navpage").GetCase.Click

    • Marked as answer by jayinthe813 Wednesday, December 11, 2013 2:33 PM
    Thursday, September 6, 2012 6:33 PM

All replies

  • Try this - I think a frame is a separate document.

    Dim frmHTMLFrame As MSHTML.HTMLDocument

    Set HTMLDoc2 = Browser.Document
    Set frmHTMLFrame = HTMLDoc2.frames(0).Document

    Do Until frmHTMLFrame.ReadyState = "complete"
    DoEvents
    Loop

    frmHTMLFrame.forms("NavPage").CNum.Value = "12345"

    frmHTMLFrame.forms("Navpage").GetCase.Click

    • Marked as answer by jayinthe813 Wednesday, December 11, 2013 2:33 PM
    Thursday, September 6, 2012 6:33 PM
  • A year later and a year wiser, I ended up moving to .NET and recoded the whole thing:

    Dim htmldoc as mshtml.htmldocument
    htmldoc = WebBrowserCtrl.Document.frames("FrameName").document
    fldInput =  htmldoc.getElementsByName("InputEleName").item(0)
    fldInput.Value = "12345"
    htmldoc.getElementsByName("BtnEleName").item(0).click()
    

    This however would be similar to how it could be done in VBA.  Just in case anyone has a similar problem or is learning how to use mshtml

    Wednesday, December 11, 2013 2:42 PM