I am still pretty new to Visual basic, but have been working to write a program for Excel that will interact with a Javascript based website and extract data from this website. The site is not mine but I have approval to extract the data I need. The problem that I'm running into is that the site contains 3 option boxes. As each box is selected the next boxes are populated with new data. Thus when I first have the program go to the site and view the code the data there is not the same after the first option is seleted. When I actually go to the site and make the seletction the source code changes, but when I make the seletction via the Visual basic code, what's shown on the screen changes but the source code for the page remains the same. I'm guessing that this has somethign to do with the postback feature of the webpage but I'm not postive if this is the case or if this is really the problem. Below i've listed both my code along with samples from the website that I'm hoping someone can point me in the right direction. Please keep in mind that I'm unable to make changes to the website. Thanks.

Sub Data_record()
Dim theItm As HTMLFormElement
URL = "http://WWw.anywebsite.com/webpage.aspx"
Set myIE = New InternetExplorer
 
With myIE
    .Navigate URL
    .Visible = True
    Do While .Busy: DoEvents: Loop
    Do While .ReadyState <> 4: DoEvents: Loop
End With
 
Set myIEdoc = myIE.document
Set theForm = findFm(myIEdoc, "ddModel")
 
        With theForm
            For i = 0 To .Length - 1
                Select Case .Item(i).Name
                    Case "ddModel"
                    .Item(i).Value = "46"
                    Case Else
                End Select
            Next
        End With
        

        With myIE 'Wait while any changes to the above seletion become availble to be seen.
            Do While .Busy: DoEvents: Loop
            Do While .ReadyState <> 4: DoEvents: Loop
        End With
        
        Set myIEdoc = myIE.document 'Ensure that myIEdoc has the latest website version.

Cells(1, 1) = myIEdoc.body.innerHTML 'This should have the source code showing the update in item ddModel to value 46.

End Sub



Function findFm(theDoc As HTMLDocument, theType As String) As HTMLFormElement
    Dim i As Integer, j As Integer
    Dim theItm As HTMLFormElement
    With theDoc.forms
        For i = 0 To .Length - 1
            Set theItm = .Item(i)
            With theItm
                For j = 0 To .Length - 1
                Testing1 = .Item(j).Name
                    If .Item(j).Name = theType Then
                        Set findFm = theItm

                        If theType = "btnSearch" Then 'used to submit final request
                            .Item(j).Click
                        End If
                        Exit Function
                    End If
                Next
            End With
        Next
    End With
End Function
<script type='text/javascript'>alert('Please enter a search criteria');</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
 <HEAD>
  <title>View / Search Site</title>
  <LINK href="styles.css" rel="stylesheet">
  <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
  <meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
  <meta content="JavaScript" name="vs_defaultClientScript">
  <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
  <script language="JavaScript" src="spell.js" type="text/javascript"></script>
  <SCRIPT language="javascript" id="clientEventHandlersJS"> 
  //=============================================== 
  //Called whenever a key is pressed and tbSearch has focus 
   
   function clickButton(e, buttonid)
   {
    var evt = e ? e : window.event;
    var bt = document.getElementById(buttonid);
         
    if (bt)
    { 
     if (evt.keyCode == 13)
     { 
      bt.click(); 
      return false; 
     } 
    } 
   }
 
  //=============================================== 
  </SCRIPT>
 </HEAD>
 <body>
  <form name="Form1" method="post" action="webpage.aspx" id="Form1">
<input type="hidden" name="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" value="Bunch of cryptic letters here" />
 
<script language="javascript" type="text/javascript">
<!--
 function __doPostBack(eventTarget, eventArgument) {
  var theform;
  if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
   theform = document.Form1;
  }
  else {
   theform = document.forms["Form1"];
  }
  theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
  theform.__EVENTARGUMENT.value = eventArgument;
  theform.submit();
 }
// -->
</script>
 
   <TABLE width="100%" align="center">
    <TR>
     <TD align="center" width="10%" bgColor="silver"><FONT size="1"><A class="menu"><a id="hlHelp" href="Help/Help.htm" target="_blank">Help on Search</a></A></FONT></TD>
     <TD align="center" width="10%" bgColor="silver"><FONT size="1"><A class="menu" href="../default.asp">Flight 
        Test Home</A></FONT>
     </TD>
     <TD align="center" width="10%" bgColor="silver"><FONT size="1"><A class="menu" href="Default.aspx">Screen 
        Main</A></FONT></TD>
     <TD align="center" width="10%" bgColor="silver"><FONT size="1"><A class="menu" href="Add.aspx">Future 
        Screen</A></FONT></TD>
     <TD width="60%">&nbsp;
     </TD>
    </TR>
   </TABLE>
   <div id="pnlSearch">
 
    <TABLE width="100%" align="center">
     <TR>
      <TD align="center" colSpan="2">
       <span id="lblHeader" style="font-size:Medium;font-weight:bold;">View/Search</span></TD>
     </TR>
    </TABLE>
    <BR>
    <TABLE>
     <TR>
      <TD align="right">
       <span id="Label3" style="font-weight:bold;">Model: </span></TD>
      <TD>
       <select name="ddModel" onchange="__doPostBack('ddModel','')" language="javascript" id="ddModel">
  <option value=""></option>
  <option value="46">1</option>
  <option value="39">2</option>
  <option value="42">3</option>
  <option value="26">4</option>
  <option value="30">5</option>
  <option value="19">6</option>
  <option value="16">7</option>
  <option selected="selected" value="27">8</option>

 
 </select><!--
      <a id="hlHeader" href="./help/help.html" target="_blank">Help</a>
      --></TD>
      <TD>&nbsp;</TD>
      <TD>&nbsp;</TD>
      <TD>&nbsp;</TD>
     </TR>
     <TR>
      <TD align="right">
       <span id="Label2" style="font-weight:bold;">No: </span></TD>
      <TD>
       <select name="ddTNo" onchange="__doPostBack('ddTNo','')" language="javascript" id="ddTNo">
  <option value=""></option>
  <option value="N103SV">N112</option>
  <option value="N105SV">N113</option>
  <option value="N272MH">N114</option>
  <option value="N616CS">N115</option>
  <option value="N680CS">N116</option>
  <option value="N681CS">N117</option>
  <option value="N682CS">N118</option>
 
 </select>
       </TD>
      <TD>&nbsp;</TD>
      <TD>&nbsp;</TD>
      <TD>&nbsp;</TD>
     </TR>
     <TR>
      <TD align="right">
       <span id="Label4" style="font-weight:bold;">S/N: </span></TD>
      <TD>
       <select name="ddSNo" onchange="__doPostBack('ddSNo','')" language="javascript" id="ddSNo">
  <option value=""></option>
  <option value="366">0</option>
  <option value="349">000001</option>
  <option value="206">000002</option>
  <option value="249">000003</option>
  <option value="265">000005</option>
  <option value="364">000016</option>
  <option value="173">000709</option>
 
 </select>
       </TD>
      <TD>&nbsp;</TD>
      <TD>&nbsp;</TD>
      <TD>&nbsp;</TD>
     </TR>
     <TR>
      <TD align="right">
       <span id="Label14" style="font-weight:bold;">Flight No: </span></TD>
      <TD>
       <select name="ddFNo" onchange="__doPostBack('ddFtNo','')" language="javascript" id="ddFNo">
  <option selected="selected" value="">All</option>
 
 </select></TD>
      <TD>&nbsp;</TD>
      <TD>&nbsp;</TD>
      <TD>&nbsp;</TD>
     </TR>
    </TABLE>
    <BR>
    <TABLE>
     <TR>
      <TD align="right">
       <span id="Label1" style="font-weight:bold;">Enter all or part of the Search Criteria. Wild cards are <B>
         <U>NOT</U></B>&nbsp;Required. </span></TD>
     </TR>
     <TR>
      <TD>
       <input name="tbSearch" type="text" id="tbSearch" OnKeyPress="return clickButton(event,'btnSearch')" style="width:416px;" /></TD>
     </TR>
     <TR>
      <TD>
       <input type="submit" name="btnSearch" value="Search" id="btnSearch" />&nbsp;
       <input type="submit" name="btnReturn" value="Return to Current screen" id="btnReturn" /></TD>
     </TR>
    </TABLE>
   
</div>
   
   </form>
 </body>
</HTML>

Wondering if this is impossible to do and thus the lack of responses or if I need to clarify something to make it more clear what the problem is.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.