0

I have created a simple form that sends data to an Excel file with an array. Everything works great except check boxes. What I would like is if the checkbox is "checked" it will post its value into the Excel document. Currently the value assigned for the box (checked) is always pasted no matter if it is checked or not. I am unsure what code is needed for the arr(6).

<script>
  function PrintFunction() {
      window.print();
  }
</script>

<script type="text/vbscript">
  function test()
    dim oApp, oWB, arr
    set oApp = CreateObject("Excel.Application")
    oApp.visible=false
    set wb = oApp.Workbooks.Open("C:\(PATH TO DB)\DB.xls",,,,"password")
    redim arr(6)

    arr(0) = Date()
    arr(1) = Form1.text1.Value
    arr(2) = Time()
    arr(3) = Form1.text2.Value
    arr(4) = Form1.text3.Value
    arr(5) = Form1.text4.Value
    arr(6) = Form1.text5.Value  <---Need help with this value

    with wb.sheets("Data").cells(1,1).currentregion
      .offset(.rows.count,0).resize(1).value = arr
    end with
    wb.close true

  x=msgbox("Submitted." ,64, "Thank you.")

    window.close()

  end function
</script>
</head>

<body oncontextmenu="return false;"> 
<form name="Form1">
<table border="0" style="width:700px;">
<td>Date:<input value="mm/dd/yyyy" name="text1" type="text" class="inputbox" size="20" />
<tr>
<td>Time:<input value="00:00 AM/PM" name="text2" type="text" class="inputbox" size="20" /></td>
<tr>
<td>Name:<input name="text3" type="text" class="inputbox" size="23"/></td>
<tr>
<td>Location:<input name="text4" type="text" class="inputbox" size="18" /></td>
<tr>
<td><input type="checkbox" name="text5" value="checked">Checkbox Title</td>
<input type="button" value="Print" class="classname" onclick="PrintFunction()" />
<input type="button" value="Submit" class="classname" onclick="test()" />
</table>
<br>
</form>

2 Answers 2

1
  1. To name a checkbox "test5" is an atrocity. Just see what it did to Josh.

  2. This

    <html>
     <head>
      <hta:application id = "cbxproblem">
      <script type="text/vbscript">
       function test()
         MsgBox Form1.cbx.checked ' <---Need help with this value
         MsgBox Form1.cbx.value
       end function
      </script>
     </head>
     <body>
      <form name="Form1">
        <input type="checkbox" name="cbx" value="pipapo" checked="checked">Checkbox Title
        <hr />
        <input type="button" value="Submit" onclick="test()" />
      </form>
     </body>
    </html>
    

    is all the code needed to present/discuss your problem. Dragging Excel and the text elements into the question is obfuscation and wasting other people's time.

  3. Reading about the checkbox element and comparing

    <input type="checkbox" name="text5" value="checked">
    

    vs.

    <input type="checkbox" name="cbx" value="pipapo" checked="checked">
    

    should make you realize the differences between the value and the checked attribute.

  4. Running the demo code will prove that the checked attribute is set to True or False depending on the user (not) marking/checking the box.

  5. See this to understand why

    If Form1.text5.Checked = True Then ' <-- nonono
    

    should be

    If Form1.text5.Checked Then
    
Sign up to request clarification or add additional context in comments.

1 Comment

I appreciate all of the input and examples. I'd rather tell someone everything I'm doing so they get the full picture ahead of time. It might be a waste of time to you, but maybe not to others. No reason to be so hostile.
0

The value of a text box is "Checked" or "Unchecked". If I understand your problem correctly, it sounds like there is another text box on the form whose value you want to copy (though I don't see it in your HTML code; maybe you need to add it?). Something like:

If Form1.text5.Checked = True Then
    arr(6) = Form1.text6.Value  'Or .Text
End If

1 Comment

Josh this helped. Thank you. I changed the text6 value back to 5 and it worked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.