Link to home
Start Free TrialLog in
Avatar of JArndt42
JArndt42Flag for United States of America

asked on

Automate a web site from Access

I have the following code. It works just fine. However I need to select a check box NOT the Select All box. I am trying to select a different load offer based on criteria I have. Any thoughts would be greatly appreciated.
Sub SteelScape()
Dim strNavigate As String
Dim objIE As Object
Dim frm As Object
Dim colInp As Object
Dim inp As Object

On Error GoTo LogError
    Set objIE = CreateObject("InternetExplorer.Application")
    strNavigate = "http://lomas.isg2tech.com/Steelscape/cgi-bin/wlogin?"

    objIE.navigate strNavigate
    objIE.Visible = True

    'allow time for the page to finish loading so I can assign userid and password
    Do While objIE.busy Or objIE.readystate <> 4
        DoEvents
    Loop

    With objIE.Document.Forms("wlogin")
        .UserId.Value = "sherman"
        .Passwd.Value = "she7845"
        .cmd.Click
    End With
    'allow time for the page to load after sign in
    Do While objIE.busy Or objIE.readystate <> 4
        DoEvents
    Loop

    'move to the page I need after the log in page
    objIE.navigate "http://lomas.isg2tech.com/Steelscape/cgi-bin/wlmt204?tstamp= 20120501081019"

    'assign the combo box on the page to Tendered
    Do While objIE.busy Or objIE.readystate <> 4
        DoEvents
    Loop
    'select all of the tendered loads and accept them
    Set frm = objIE.Document.Forms("wlmt204")

    With frm
        .pstat.Value = "T"
        .submit
    End With
    
    Do While objIE.busy Or objIE.readystate <> 4
        DoEvents
    Loop
    Set frm = objIE.Document.Forms("wlmt204")

    frm.selall.Click

    Do While objIE.busy Or objIE.readystate <> 4
        DoEvents
    Loop

    Set frm = objIE.Document.Forms("wlmt204")

    Set colInp = frm.getelementsbytagname("INPUT")

    For Each inp In colInp
        'Debug.Print inp.Value
        If inp.Value = "Accept Selected Loads" Then Exit For
    Next inp
    inp.Click

ExitPoint:
    Set objIE = Nothing
    On Error GoTo 0
    Exit Sub
LogError:
    Call LogError(Err.Number, Err.Description, "CSA2010 Error", , True)
    objIE.Quit
    Resume ExitPoint
End Sub

Open in new window

Avatar of IrogSinta
IrogSinta
Flag of United States of America image

First off, are you sure it's okay to have a login and password in the code you provided?
Secondly, what do you mean by load offer and what criteria are you referring to?
Avatar of JArndt42

ASKER

Irog, Thank your for your concern. It is OK as it is not sensitive information. The log on is merely so that the trucking companies can select loads and it assigns them to the correct company. Here is some of the source code of the web site when it is has loads to tender. Note that the select all and then two check boxes with loads to be tendered. I want to be able to select only one of the boxes where name="hsload" value="1217351"> is the pick up number I get from a notification email. The process is such, and it works with the select all fyi. I get an email notification about a load offer. I have a procedure that checks the email to make sure the load offer meets the criteria we need. If so then it opens the website, signs on, selects all and accepts them. I do NOT want it to select all. I want ONLY the one where the source code name="hsload" value="1217351"> is the same as the one I pulled out of the email. How do I select just the one load?

 <TD class="header" align="center"><INPUT TYPE="checkbox" NAME="selall" onclick="selectAll();"></TD>
<TD class="header" align="center">Load<BR>Number</TD>
<TD class="header" align="center">Pro<BR>Number</TD>
<TD class="header" align="center">Shipper</TD>
<TD class="header" align="center">Consignee</TD>
<TD class="header" align="center">Equipment<BR>Type</TD>
<TD class="header" align="center">Estimated<BR>Weight(Lbs)</TD>
<TD class="header" align="center">Accepted<BR>Weight<br>(Lbs)</TD>
<TD class="header" align="center">Estimated<BR>Miles</TD>
<TD class="header" align="center">Earliest <BR>Delivery<br>Date</TD>
<TD class="header" align="center">Pickup Date</TD>
<TD class="header" align="center">Delivery Date</TD>
<TD class="header" align="center">Tender Date</TD>
<TD class="header" align="center">Status</TD>
<TD class="header" align="center">Freight<BR>Resp.</TD>
<TD class="header" align="center">Notes</TD>
</TR>
<TR>
<TD class="row1" align="center" ><INPUT TYPE="checkbox" NAME="sel" VALUE="001KAS1 12173510130" style="" ></TD>
<TD class="row1" >1217351
<INPUT type="hidden" name="hskey" value="001KAS1 12173510130">
<INPUT type="hidden" name="hsload" value="1217351">
<INPUT type="hidden" name="h1weig" value="35,530">
</TD>
<TD class="row1" align="center" ><INPUT maxLength="21" size="10" name="wspro" value=""></TD>
<TD class="row1" nowrap valign="top" >STEELSCAPE KALAMA<BR>PO BOX 606<BR>KALAMA, WA 98625</TD>
<TD class="row1" nowrap valign="top" >ASCD - ASC PROFILES<BR>2110 ENTERPRISE BLVD<BR>W. SACRAMENTO, CA 95691</TD>
<TD class="row1" align="center" >Regular Flatbed</TD>
<TD class="row1" align="center" >35,530</TD>
<TD class="row1" align="center" >35530</TD>
<INPUT type="hidden" name="wscnac" value="35530">
<INPUT type="hidden" name="h1err" value="">
<TD class="row1" align="center" >615</TD>
<TD class="row1" align="center" nowrap style="background-color: red;">9/06/12</TD>
<TD class="row1" align="center" nowrap style="background-color: red;">9/06/12</TD>
<TD class="row1" align="center" nowrap ></TD>
<TD class="row1" align="center" nowrap >09/06/12 7:51</TD>
<TD class="row1" align="center" >Tendered</TD>
<TD class="row1" align="center" >S</TD>
<TD class="row1" >&nbsp;</TD>
</TR>
<TR>
<TD class="row2" align="center" ><INPUT TYPE="checkbox" NAME="sel" VALUE="001KAS1 12174340130" style="" ></TD>
<TD class="row2" >1217434
<INPUT type="hidden" name="hskey" value="001KAS1 12174340130">
<INPUT type="hidden" name="hsload" value="1217434">
<INPUT type="hidden" name="h1weig" value="35,600">
</TD>
<TD class="row2" align="center" ><INPUT maxLength="21" size="10" name="wspro" value=""></TD>
<TD class="row2" nowrap valign="top" >STEELSCAPE KALAMA<BR>PO BOX 606<BR>KALAMA, WA 98625</TD>
<TD class="row2" nowrap valign="top" >ASCD - ASC PROFILES<BR>2110 ENTERPRISE BLVD<BR>W. SACRAMENTO, CA 95691</TD>
<TD class="row2" align="center" >Regular Flatbed</TD>
<TD class="row2" align="center" >35,600</TD>
<TD class="row2" align="center" >35600</TD>
<INPUT type="hidden" name="wscnac" value="35600">
<INPUT type="hidden" name="h1err" value="">
<TD class="row2" align="center" >615</TD>
<TD class="row2" align="center" nowrap style="background-color: red;">9/06/12</TD>
<TD class="row2" align="center" nowrap style="background-color: red;">9/06/12</TD>
<TD class="row2" align="center" nowrap ></TD>
<TD class="row2" align="center" nowrap >09/06/12 7:51</TD>
<TD class="row2" align="center" >Tendered</TD>
<TD class="row2" align="center" >S</TD>
<TD class="row2" >&nbsp;</TD> 

Open in new window

Sorry that I didn't get back to you right away.  I'm not sure if you've already found the answer or are still looking, but if the latter, this seems to work.  I stuck it in place of lines 48 to 54 in your original post:

    Dim Doc As HTMLDocument
    Set Doc = objIE.Document
    Set colInp = Doc.getElementsByName("sel")
    For Each inp In colInp
        'Debug.Print inp.Value
        If InStr(inp.Value, "1217350") > 0 Then
            inp.Checked = True
        End If
    Next inp

Open in new window

You just need to add a Reference to Microsoft HTML Object Library
ASKER CERTIFIED SOLUTION
Avatar of IrogSinta
IrogSinta
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you for that. works like a charm. appreciate your assistance.