Insert Radio value to Boolean field in Table

I Have three radio groups, and 3 tables in an Access Database, each with a field called "WhatsNew"(Boolean).  I would like to insert the value "TRUE" into the appropriate record where my recordset field "Headline" matches the Database field "Headline".  
   Here is the base code for one radio group scenerio, I will do the same with the other two once these get working.

<form method = "post" action = "Default2.asp" name= "WhatsNew">
<h1>News</h1>
<%
                  Set Conn = Server.CreateObject("ADODB.Connection")
                  Conn.Open "DSN=yohalem"
                  sql="SELECT * FROM news"
                  Set RS = Conn.Execute(sql)
                  RS.MoveFirst%>
                  <% Do While Not RS.EOF %>
            <table border="0" align="center" width="100%">
              <tr>
                <td height="23" width="3%" valign="top"><INPUT type="radio" value=<%= RS("Headline") %> name=radio_news></td>
                <td valign="top" height="23" width="97%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b><a href="news2.asp?id=<%= RS("id") %>"><%= RS("Headline") %></a></b></font></td>
              </tr>
            </table>
            <% RS.MoveNext %>
            <% Loop %>
<INPUT type="submit" value="Change Whats New" name=cmdSubmit>
</Form>
 
Now I need an Insert Statment mostlikly in a procedure, that selects the record accouring to the Headline and sets the WhatsNew field to true.  I also need to call that procedure from the form upon submit(Which is easy but I forget and have no references right now)

LVL 1
khagenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

khagenAuthor Commented:
Adjusted points to 100
0
khagenAuthor Commented:
Here's What I have,

<SCRIPT Language = VBSCRIPT>
Sub cmdWhatsNew_OnClick
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "DSN=yohalem"
                  
sqlNews = "Insert into News.Comment("Keith") where News.Headline =" Radio_news.value

Conn.Execute sqlNews

Alert("The Whats New Newsboard has been updated")

End Sub
</Script>


I don't think I am referencing my RadioGroup properly, and I'm working with a text field right now, and will change to boolean once I have it.
0
mgfranzCommented:
It is my experience that the radio button select feeds a boolean value by default, or is that a check box...

Whats your psuedo code for the above?

Mark
0
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

khagenAuthor Commented:
My psuedo code is;

I have no pseudo code, I am still looking for some direction to take.  I want to capture the value of the three radio groups, preferably in three variables of type boolean and then send them to the data base.  I work on some psuedo code then post it.
0
mgfranzCommented:
How are you defining the group name?  Your example only identifies one group.
0
khagenAuthor Commented:
Ok I have figured it out.  Now I have related question.  Right now, I chose a radio button, and it sets the data field to true in the database, so it workd.  However, when i do another test, if I chose another radio button, a second record in the table is set to true, making two records, where as I only want one.  How can I ensure the table has only one record with that field chosen at a time, and have the radio buttons reflect the current record chosen?

Here is how I am currently updating the table to set the boolean field to true for the appt record;

Set ConnNews = Server.CreateObject("ADODB.Connection")
ConnNews.Open "DSN=yohalem"
sqlNews = "UPDATE News SET WhatsNew ="&true&" Where ID ="&Request.Form("radio_news")
ConnNews.Execute(sqlNews)
ConnNews.Close
Set ConnNews = Nothing
0
khagenAuthor Commented:
I guess, limiting the field to only one true record is more of an Access issue, but how can i ensure that the form is reflective of whats in the database?
0
mgfranzCommented:
This is an Access issue, of which I can't help you with.  Sorry.
0
khagenAuthor Commented:
I have coded the VBA in a module, I just need to know how to call it.  Can I call a Access Procedure from ASP?
0
AemerginCommented:
Not as far as I know, khagen. MS Access doesn't handle procedures the same way as MS SQL/Oracle/etc. You'll have to write sub routines in your ASP code to emulate stored procedures. It won't be as fast, but if you're using MS Access, you most likely won't notice the additional time it takes.

I did notice that you are trying to write sub routines in ASP that only work in VB .. if you want an onclick, you have to write the subroutine and then define the onclick in your form element.

Another thing I saw was that when you try to reference the values in your form, you are using the VB way, not the ASP way. You need to specify "Request.Form("element_name")" instead of "element_name.value".

I hope any or all of this helps!

-Aemergin
0
khagenAuthor Commented:
Thanks, all those VB VB script things were pretty early on.  I have learned alot today.  Thanks for letting me know that I have to write server side script.  Here is my VBA basics.  How would this work in ASP?

Public Sub WhatsNew()
Dim Field As Boolean
Dim rs As Recordset
Dim varValid As Integer
Dim varID As Integer
'This to ensure that only one record has a true WhatsNew
Set rs = CurrentDb.OpenRecordset("Select WhatsNew From News")
rs.MoveFirst
varValid = 0
Do Until rs.EOF

Field = rs("WhatsNew")
If Field = True Then
    varValid = varValid + 1
    If varValid > 1 Then
        rs.Edit
        rs!WhatsNew = False
        rs.Update
    End If
End If
rs.MoveNext
Loop
End Sub
0
mgfranzCommented:
Try this;

Sub WhatsNew()
Dim Field, rs, ojbDC, varValid, varID, sql

'This to ensure that only one record has a true WhatsNew
' For DSNless connection use this;
Set objDC = Server.CreateObject("ADODB.Connection")
objDC.ConnectionTimeout = 30
objDC.CommandTimeout = 60
objDC.Open "DBQ=" & Server.MapPath("your.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};"
Set rs = Server.CreateObject("ADODB.Recordset")
sql = ("Select WhatsNew From News")
rs.MoveFirst
varValid = 0
Do Until rs.EOF

Field = rs("WhatsNew")
If Field = True Then
    varValid = varValid + 1
    If varValid > 1 Then
        'rs.Edit
        rs.WhatsNew = False
        rs.Update
    End If
End If
rs.MoveNext
Loop
End Sub

Untested...
0
mgfranzCommented:
Oops, forgot to open the rs;

Set rs = Server.CreateObject("ADODB.Recordset")
sql = "Select WhatsNew From News;"
rs.Open sql, objDC, 3, 3
....
0
khagenAuthor Commented:
Thanks,
The code was pretty good, I just had to change some recordset stuff.  While I'm on here,(and you can lock me If you like), do you know of a way of seting a radio button to true.  As you know, I'm retrieving values from a database, and when I first open the page with the radio buttons, I would like the radio buttons to accuratly represent which record in the tablw is currently set to true.  

The psuedo code is;

IF WhatsNew is True Then
     Set the current radio button to True
End If

I would intergrate it into this code;

<%Do While Not RSNews.EOF %>
            <table border="0" align="center" width="100%">
              <tr>
                <td height="23" width="3%" valign="top">
                              <INPUT type="radio" value=<%= RSNews("id") %> name=radio_news></td>
                <td valign="top" height="23" width="97%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>
                              <a href="news/news.asp?id=<%= RSNews("Headline") %>"><%= RSNews("Headline") %></a></b></font></td>
              </tr>
            </table>
            <% RSNews.MoveNext %>
            <% Loop %>

0
mgfranzCommented:
Since the value of the radio button will be either true of false in the dB anyway, all you will have to do is check the value;

<%
sql = "select * from table"

if <%RSNews("WhatsNew")%> = "True" Then
%>
<table border="0" align="center" width="100%">
              <tr>
                <td height="23" width="3%" valign="top">
<INPUT type="radio" value=<%= RSNews("id") %> name=radio_news></td>
                <td valign="top" height="23" width="97%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>
<a href="news/news.asp?id=<%= RSNews("Headline") %>"><%= RSNews("Headline") %></a></b></font></td>
              </tr>
            </table>
            <% RSNews.MoveNext %>
            <% Loop %>
<ElseIf <%RSNews("WhatsNew")%> = "False" Then
%>
Do something else...

Essentially all you want to do is check the value of the field, if true do something, if false, do something else.  No need to Set the button value, unless you need it as an object.  You can put this loop in a sub for simplicity.

Mark
0
khagenAuthor Commented:
How is that different than this?

<%
                  Set Conn = Server.CreateObject("ADODB.Connection")
                  Conn.Open "DSN=yohalem"
                  sql="SELECT * FROM news"
                  Set RSNews = Conn.Execute(sql)
                  %>
                  <%Do While Not RSNews.EOF %>
            <table border="0" align="center" width="100%">
              <tr>
                <td height="23" width="3%" valign="top">
                              <INPUT type="radio" value=<%= RSNews("id") %> name=radio_news></td>
                <td valign="top" height="23" width="97%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>
                               <%Response.Write(RSNews("Headline"))%></b></font></td>
              </tr>
            </table>
            <% RSNews.MoveNext %>
            <% Loop %>
       
         
It seems to me that your saying the option button should already be selected because the value is being set to true due to that value being passed as true from the database.  Is that right?
0
mgfranzCommented:
No, how does the line;
<INPUT type="radio" value=<%= RSNews("id") %> name=radio_news></td>

know that the value is true?  In my example, I stated to run the above only if the value is true, if is false you would run a different loop.

In other words, (psuedo code);

If value of button field is true,
  Do this

Else value of button is false,
  Do this instead
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.