Forums
This topic is locked
Changin TRUE to FALSE and viceversa in one step
Posted 30 Aug 2002 15:31:47
1
has voted
30 Aug 2002 15:31:47 Ivan Halen posted:
Hello!I slightly modified a portion of code from the Multidelete extension by Piero Mattirolo in this way:
dim strID
strID=Request("checkbox"

if strID <>"" then
dim sql
sql="UPDATE UserLogin SET UserToggle = True WHERE UserID IN "
sql=sql &"(" & strID & "

set Command1 = Server.CreateObject("ADODB.Command"

Command1.ActiveConnection = MM_connWC_STRING 'connection string
(notice that the SQL query is not "DELETE...": that's what I modified)
As you can see, this code sets fields from UserToggle column to TRUE (it's a "yes/no" Access2000 column), according to UserID values that were passed by a checkbox (that's the same of the original tutorial about Deleting by Checkboxes that you can fine on UDZone)
Well, 'til here no problem...
But what should I do to set to TRUE values that are FALSE, and to FALSE values that are TRUE, in one step? I've in mind something like this:
"UPDATE UserLogin SET UserToggle = [TRUE if it's FALSE, FALSE if it's TRUE] WHERE UserID, ecc.."
I just don't know where to begin! Anyone can help? Thank you!
Replies
Replied 30 Aug 2002 15:58:23
30 Aug 2002 15:58:23 Owen Eastwick replied:
I don't think you can do it in on hit, but this should do the trick:
Create 2 recordsets:
Recordset1.Source = "SELECT RecordID FROM TableName WHERE YourFieldName LIKE 'TRUE'"
Recordset2.Source = "SELECT RecordID FROM TableName WHERE YourFieldName LIKE 'FALSE'"
Collect the RicordID's and store them in two strings:
<%
While NOT Recordset1.EOF
If str1 = "" Then
str1 = str1 & "(" & Recordset1.Fields.Item("RecordID"
.Value
Else
str1 = str1 & ", " & Recordset1.Fields.Item("RecordID"
.Value
End If
Wend
str1 = str1 & "
"
%>
Do the same for Recordset 2, this will create 2 strings of RecordID's something like: (1, 5, 9, 15, 22)
Then create 2 update commands something like:
<%
set Command1 = Server.CreateObject("ADODB.Command"
Command1.ActiveConnection = MM_ASMEconn_STRING
Command1.CommandText = "UPDATE TableName SET YourFieldName = 'FALSE' WHERE RecordID IN " &str1
Command1.CommandType = 1
Command1.CommandTimeout = 0
Command1.Prepared = true
Command1.Execute()
%>
and another for changing the TRUE's to FALSE
Regards
Owen.
Multiple Parameter UD4 / Access 2000 Database Search Tutorial:
www.tdsf.co.uk/tdsfdemo
Create 2 recordsets:
Recordset1.Source = "SELECT RecordID FROM TableName WHERE YourFieldName LIKE 'TRUE'"
Recordset2.Source = "SELECT RecordID FROM TableName WHERE YourFieldName LIKE 'FALSE'"
Collect the RicordID's and store them in two strings:
<%
While NOT Recordset1.EOF
If str1 = "" Then
str1 = str1 & "(" & Recordset1.Fields.Item("RecordID"

Else
str1 = str1 & ", " & Recordset1.Fields.Item("RecordID"

End If
Wend
str1 = str1 & "

%>
Do the same for Recordset 2, this will create 2 strings of RecordID's something like: (1, 5, 9, 15, 22)
Then create 2 update commands something like:
<%
set Command1 = Server.CreateObject("ADODB.Command"

Command1.ActiveConnection = MM_ASMEconn_STRING
Command1.CommandText = "UPDATE TableName SET YourFieldName = 'FALSE' WHERE RecordID IN " &str1
Command1.CommandType = 1
Command1.CommandTimeout = 0
Command1.Prepared = true
Command1.Execute()
%>
and another for changing the TRUE's to FALSE
Regards
Owen.
Multiple Parameter UD4 / Access 2000 Database Search Tutorial:
www.tdsf.co.uk/tdsfdemo
Replied 30 Aug 2002 16:17:03
30 Aug 2002 16:17:03 Ivan Halen replied:
Thank you! Usign 2 recordset (and so two HTML tables, one for records set to TRUE, the other for Records set to FALSE) is a good idea: my idea was that I could have all the items (TRUEs and FALSEs) listed in one table, but I guess that's impossible...
Anyway, using two recordset it's easier: I can send one Recordset to a page that will set TRUEs to FALSEs, and the other Recordset to another page, that does the viceversa operation...
That's good! Thank you!
Anyway, using two recordset it's easier: I can send one Recordset to a page that will set TRUEs to FALSEs, and the other Recordset to another page, that does the viceversa operation...
That's good! Thank you!
Replied 30 Aug 2002 18:27:58
30 Aug 2002 18:27:58 Ivan Halen replied:
oeastwick, they gave me another solution, much moooooooore easy!!!!
Simply change this:
"UPDATE UserLogin SET UserToggle = True WHERE..."
with this:
"UPDATE UserLogin SET UserToggle = NOT UserToggle WHERE..."
easier, isn't it? <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
Simply change this:
"UPDATE UserLogin SET UserToggle = True WHERE..."
with this:
"UPDATE UserLogin SET UserToggle = NOT UserToggle WHERE..."
easier, isn't it? <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
