Cycle thru radio buttons in web form with VBA

Dude

Board Regular
Joined
Jan 12, 2006
Messages
80
I have some code that logs me into a customer site and i get a large form with a bunch of options that need to be chosen. I have isolated the form I need to use "document.ConsignmentForm()" but it has 6 radio buttons and a submit button.
I have been able to submit the form with the default "Checked Name" button but I cant figure out how to cycle through the other button values eg. RB_RPT2, RB_RPT3, etc. etc. etc.

Have tried all kinds of clumsy floundering around in the dark, wonder if someone can point me to the light ?


Thanks


Code:
function SetDate () {
document.cookie = "frdate=" + document.ConsignmentForm.elements[8].value + ';path=/';
//document.cookie = "frdate=" + document.FORM1.elements[8].value + ';path=/'; 
//document.cookie = "todate=" + document.ConsignmentForm.elements[9].value + ';path=/';
document.cookie = "todate=" + document.ConsignmentForm.elements[8].value + ';path=/';   
}
//--> 
    </script><o:p> </o:p></p>
    <form action="https://portal.pwc.ca/scripts/wgate/" method=POST
    enctype="application/x-www-form-urlencoded">
    <p class=MsoNormal><span style='display:none;mso-hide:all'><INPUT TYPE="hidden" NAME="~PASSWORD[1]"></span><span
    style='display:none;mso-hide:all'><INPUT TYPE="hidden" NAME="~LOGIN[1]"></span><o:p></o:p></p>
    <div align=center>
    <table class=MsoNormalTable border=0 cellspacing=1 cellpadding=0
     style='mso-cellspacing:.7pt'>
<!--- <tr>
			<td class="gNewItem" style="font-size:larger;">Note:</td>
			<td colspan="3"  style="font-weight:bold;color:navy;">The Month-end Stock is as the Mar 01</td>
		</tr> --->
     <tr style='mso-yfti-irow:0'>
      <td style='padding:.75pt .75pt .75pt .75pt'>
      <p class=MsoNormal>Stocks </p>
      </td>
      <td style='padding:.75pt .75pt .75pt .75pt'>
      <p class=MsoNormal><INPUT TYPE="radio" CHECKED NAME="RADC_%R%102" VALUE="RB_RPT1"></p>
      </td>
      <td style='padding:.75pt .75pt .75pt .75pt'>
      <p class=MsoNormal>Receipts </p>
      </td>
      <td style='padding:.75pt .75pt .75pt .75pt'>
      <p class=MsoNormal><INPUT TYPE="radio" NAME="RADC_%R%102" VALUE="RB_RPT2"></p>
      </td>
     </tr>
     <tr style='mso-yfti-irow:1'>
      <td style='padding:.75pt .75pt .75pt .75pt'>
      <p class=MsoNormal>Issues </p>
      </td>
      <td style='padding:.75pt .75pt .75pt .75pt'>
      <p class=MsoNormal><INPUT TYPE="radio" NAME="RADC_%R%102" VALUE="RB_RPT3"></p>
      </td>
      <td style='padding:.75pt .75pt .75pt .75pt'>
      <p class=MsoNormal>Process for payment </p>
      </td>
      <td style='padding:.75pt .75pt .75pt .75pt'>
      <p class=MsoNormal><INPUT TYPE="radio" NAME="RADC_%R%102" VALUE="RB_RPT4"></p>
      </td>
     </tr>
     <tr style='mso-yfti-irow:2'>
      <td style='padding:.75pt .75pt .75pt .75pt'>
      <p class=MsoNormal>Month-end Stock </p>
      </td>
      <td style='padding:.75pt .75pt .75pt .75pt'>
      <p class=MsoNormal><INPUT TYPE="radio" NAME="RADC_%R%102" VALUE="RB_RPT5"></p>
      </td>
      <td style='padding:.75pt .75pt .75pt .75pt'>
      <p class=MsoNormal>Previous Month-end Stock </p>
      </td>
      <td style='padding:.75pt .75pt .75pt .75pt'>
      <p class=MsoNormal><INPUT TYPE="radio" NAME="RADC_%R%102" VALUE="RB_RPT5A"></p>
      </td>
     </tr>
 
Dude

It's still unclear where you are getting the error.

Which line of code is it?
 
Upvote 0

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Think I've got it, well partially anyway.
Code:
Sub PWlogin()
Dim ie As InternetExplorer
Dim PWPage As Object
Dim Form As Object
Dim HtmlDoc
Dim RB As Object 'HTMLInputElement

Set ie = New InternetExplorer
With ie
    .Navigate "c:\consignment.htm"
    Do While .busy: DoEvents: Loop
    Do While .ReadyState <> 4: DoEvents: Loop
    .Visible = True

    Do While .busy: DoEvents: Loop
    Do While .ReadyState <> 4: DoEvents: Loop
    
    Set HtmlDoc = .document.forms(0) ' create a reference to the first/only form in the document
   
    Set RB = HtmlDoc.Item("RADC_%R%102") ' create a reference to the option group RADC_%R%102
    
    RB(3).Checked = True ' check the 4th item in the option group
    
    HtmlDoc.submit
    
    Do While .busy: DoEvents: Loop
    Do While .ReadyState <> 4: DoEvents: Loop

End With
Set ie = Nothing
End Sub
 
Upvote 0
allways where i try to assign a value for the form input

example:

Code:
            With .document.ConsignmentForm() 
                .RADC_%R%102.value = "RB_RPT2" 
                .submit
            End With

Error would be on the line that starts- .RADC_%R% etc. etc..

If I try;

Code:
            With .document.ConsignmentForm.Item("RADC_%R%102")
                .value = "RB_RPT2" 
                .submit
            End With

It says "Object doesn't support this Property or Method" . The error is in the same place, .Value = "RB_RPT2" . anywhere I have tried to assign some type of value.
 
Upvote 0
AWESOME
Norie you are the king.

I tried it and it didn't work. I made some (ever so slight) modifications and poof there you go it works. Now I just need to loop through all 6 and get a file downloaded from each one.

I just excised this snippet :

Code:
    Set HtmlDoc = .document.ConsignmentForm() ' create a reference to the first/only form in the document "Modified to the form I need it to reference" 
    
    Set RB = HtmlDoc.Item("RADC_%R%102") ' create a reference to the option group RADC_%R%102
    
    RB(3).Checked = True ' check the 4th item in the option group
    
    HtmlDoc.submit
    
    Do While .busy: DoEvents: Loop
    Do While .ReadyState <> 4: DoEvents: Loop

Pasted it under the Login portion and what do you know, it did just as advertized.


Once again Norie, Tightwad THANKS I am self taught in VBA and only post a question as a last resort. Researching an answer to this problem has led me to many places/ forums and and i have found the name Norie in more than one.

Once again THANKS !!!
I will go to work now trying to get the rest of it done.
 
Upvote 0
Dude

Here's how you can loop through each option.
Code:
For Each RBOpt In RB
    
        RBOpt.Checked = True
        HtmlDoc.submit
        
Next RBOpt
 
Upvote 0
Norie
Would love to use that. As a matter of fact I am going to clip it and save for later.
But I have to download a file from a popup window that comes up when each option is submitted. Each report unfortunately has to be downloaded to a different directory because the server names them all the same, otherwise they would all overwrite eachother.

I really need to submit RB(0) then download file to directory A then close popup window and submit RB(1) and so on and so on.

The server popup window is allways the same URL (https://portal.pwc.ca/scripts/wgate/)
just the data (report) it displays is different. I believe the part I am looking for is

var delfile = "/" + syst + "/mm/PWC_consignment_" + username + FileExt;

It looks to me that if you have Netscape it will deliver it in .csv versus .gz for IE.

I will have to change that to deliver it in .csv with IE so I can save a step uncompressing it.

Like I said, I am just poking around, I could be wrong as to what parts are important.

By the way the next to last line
" ><nobr id=l0001002>2006.10.09 PROCESS FOR PAYMENT REPORT</nobr> "
Is the report Title. If that means anything.

Rich (BB code):
<script>
 function NetChk() { 
 if (browser == 'Netscape') { 
    pop = "";  
    cookie = document.cookie;
    cookies = cookie.split(";");
    for (i in cookies) {j = cookies.indexOf("pop=");
    if (j != -1) {pop = cookies.substring(j + 4);} } 
    if (pop != "ok") {window.alert("To Download using Netscape  \n\n" +  
    "\t 1. Position your mouse pointer over the DOWNLOAD button \n" + 
    "\t 2. Right Mouse Click and \n" + 
    "\t 3. Select the Save Link As... option from the selection window\n" + 
    "\t 4. Save your report locally."); 
    document.cookie = "pop=ok" + ';path=/';  }  }  } 
 function sortie() {
	username = "";
	cookie = document.cookie;
	cookies = cookie.split(";");
	for (i in cookies) {j = cookies.indexOf("username=");
	if (j != -1) {
	username = cookies.substring(j + 9);}}
		syst = "";
		cookie = document.cookie;
		cookies = cookie.split(";"); 
		for (i in cookies) {j = cookies.indexOf("syst=");
		if (j != -1) {syst = cookies.substring(j + 5);}}
		var browser = navigator.appName;
		var version = navigator.appVersion; 
		var FileExt = ".gz ";
		if (browser == 'Netscape') {FileExt = ".csv ";}
		var delfile =  "/" + syst + "/mm/PWC_consignment_" + username + FileExt; 
		document.FORMDEL.elements[0].value=delfile;
		document.FORMDEL.submit();}
		//function bypass() {//var bypass="y"; 
		//alert("bypass");
		//} 
</script>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="2050"/>
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1"/>
 </o:shapelayout></xml><![endif]-->
</head>

<body bgcolor=white lang=EN-US link="#6666FF" vlink=red style='tab-interval:
.5in' marginheight=5 marginwidth=10 topmargin=0 bottommargin=0 rightmargin=0
leftmargin=10>

<div class=Section1>

<table class=MsoNormalTable border=0 cellspacing=0 cellpadding=0 width=674
 style='width:505.5pt;mso-cellspacing:0in;mso-padding-alt:0in 0in 0in 0in'>
 <tr style='mso-yfti-irow:0;mso-yfti-lastrow:yes'>
  <td width=469 valign=bottom style='width:351.75pt;padding:0in 0in 0in 0in'>
  <p class=MsoNormal>
		
		
	


	
F:\sap\its\mimes\ebc\images\bande-moteur.gif
</p> </td> <td width=205 valign=bottom style='width:153.75pt;padding:0in 0in 0in 0in'> <p class=MsoNormal>
F:\sap\its\mimes\ebc\images\logo-pratt.gif
</p> </td> </tr> </table> <p class=MsoNormal><span style='display:none;mso-hide:all'><o:p> </o:p></span></p> <table class=MsoNormalTable border=0 cellspacing=0 cellpadding=0 width=695 style='width:521.25pt;mso-cellspacing:0in;mso-padding-alt:0in 0in 0in 0in'> <tr style='mso-yfti-irow:0;mso-yfti-lastrow:yes'> <td width=155 valign=top style='width:116.25pt;padding:0in 0in 0in 0in'> <p class=MsoNormal>
F:\sap\its\mimes\ebc\images\nav01-01.gif
</p> </td> <td valign=top style='padding:0in 0in 0in 0in'> <p class=MsoNormal>
F:\sap\its\mimes\ebc\images\nav01-08.gif
</p> </td> </tr> </table> <p class=MsoNormal><span style='display:none;mso-hide:all'><o:p> </o:p></span></p> <table class=MsoNormalTable border=0 cellspacing=0 cellpadding=0 width=741 style='width:555.75pt;mso-cellspacing:0in;mso-padding-alt:0in 0in 0in 0in'> <tr style='mso-yfti-irow:0'> <td width=500 valign=top style='width:375.0pt;padding:0in 0in 0in 0in'> <p class=MsoNormal>
F:\sap\its\mimes\ebc\images\titresiblanc.gif
</p> </td> <td width=280 rowspan=3 valign=top style='width:210.0pt;padding:0in 0in 0in 0in'> <table class=MsoNormalTable border=0 cellspacing=1 cellpadding=0 style='mso-cellspacing:.7pt'> <tr style='mso-yfti-irow:0'> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal>
F:\sap\its\mimes\ebc\images\bidon.gif
</p> </td> </tr> <tr style='mso-yfti-irow:1;mso-yfti-lastrow:yes'> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal><script> username = ""; cookie = document.cookie; cookies = cookie.split(";"); for (i in cookies) {j = cookies.indexOf("username="); if (j != -1) {username = cookies.substring(j + 9);}} syst = ""; cookie = document.cookie; cookies = cookie.split(";"); for (i in cookies) {j = cookies.indexOf("syst="); if (j != -1) {syst = cookies.substring(j + 5);}} var browser = navigator.appName; var version = navigator.appVersion; var FileExt = ".gz "; var alternate = ""; if (browser == 'Netscape') {var alt1 = "The DOWNLOAD feature is only available via the Save As Link option. Activated" + " by Mouse Right Click." ; var alternate = "ALT=" + '"' + alt1 + '"'; FileExt = ".csv ";} var download = "<A HREF=/mmout/PWC_consignment_" + username + FileExt + " onMouseOver=NetChk() >"; document.write(download); var image="<img src=/sap/its/mimes/ebc/button/si-download.jpg border=0 " + alternate + "></a>"; document.write(image); </script></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal><a href="file:///F:\scripts\misc\closewindow.html"><span style='text-decoration:none;text-underline:none'>
F:\sap\its\mimes\ebc\button\si-close.jpg
</span></a></p> </td> </tr> </table> <p class=MsoNormal><o:p></o:p></p> </td> </tr> <tr style='mso-yfti-irow:1'> <td width=491 valign=top style='width:368.25pt;padding:0in 0in 0in 0in'> <p class=MsoNormal>
F:\sap\its\mimes\ebc\images\st-sireports.gif
</p> </td> </tr> <tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'> <td width=491 valign=top style='width:368.25pt;padding:0in 0in 0in 0in'> <p class=MsoNormal>
F:\sap\its\mimes\ebc\images\st-ombre.gif
</p> </td> </tr> </table> <blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'> <p class=MsoNormal><o:p> </o:p></p> <form> <!heading!><!reportname!> <p class=MsoNormal><span style='display:none;mso-hide:all'><INPUT TYPE="hidden" NAME="temp"><!selection_screen!></span></p> </form> <span style='font-size:8.0pt'>  </span><span style='font-size:8.0pt;font-family:monospaced'><o:p></o:p></span></p> <pre><nobr id=l0001002>2006.10.09 PROCESS FOR PAYMENT REPORT</nobr> <nobr id=l0002002>__________ __________________________</nobr><o:p></o:p></pre>
 
Upvote 0
Dude

The code I posted isn't really anything to do with downloading.:)

It's just to show you how you would cycle through the options.

You'll need other code for downloading, which you might find if you do a board search.

I'm sure I've seen a thread dealing with that issue recently.
 
Upvote 0
I realize it is not for downloading I was just stating that I would have to put something a little more in between, just cant loop straight through each.

I understand what you gave me though.

Thanks again.
 
Upvote 0
Dude

No problem, just wanted to clarify.:)
 
Upvote 0

Forum statistics

Threads
1,216,075
Messages
6,128,662
Members
449,462
Latest member
Chislobog

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top