Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update Two Fields with Subroutine

Status
Not open for further replies.

DonP

IS-IT--Management
Jul 20, 2000
684
US
I have a simple subroutine that is working fine for inserting multiple entries from a loop, into a single field in the MS-SQL table:

[tt]Sub AddRecord( value )
DataConn.Execute = "INSERT into services (ID, type) " &_
"VALUES (" & Session("ID") & ", " & value & ")"
End Sub
[/tt]

But I want it to insert values for two fields and it refuses to do it!

[tt]Sub AddRecord( value, fee )
DataConn.Execute = "INSERT into services (ID, type, fee) " &_
"VALUES (" & Session("ID") & ", " & value & ", " & fee & ")"
End Sub
[/tt]

I am looping through the recordset like this:

[tt]rslookup.MoveFirst
do while not rslookup.EOF
ID = rslookup("ID")
Fee = Request("Fee")
If Request(ID) = 1 then
AddRecord ID, FEE
End if
rslookup.MoveNext
loop
[/tt]

I've tried it both with parenthesis: AddRecord(ID, FEE) and without: AddRecord ID, FEE

With them, it crashes and without them, it does not but neither does it insert anything. The original value was from a checkbox while the second one is from a text field and with the change, even the checkbox no longer inserts when it was working before. What do I try next? I've exhaused all I can think of. Don
don@pc-homepage.com
Experienced in HTML, Perl, VBScript, PWS, IIS and Apache. Run OS/2 Warp 4, BeOS v5 and Windows NT/2000 (only when I have to!)
 
Donp,

If the Record alread exists, then you need to "SELECT the record,

"strSQL = "SELECT * FROM MyTable WHERE id=" & id

Once you retrieve all the records that match your SELECT statement, then you can update those field that you want like below.

rslookup.MoveFirst
rslookup("type") = type
rslookup("fee") = fee
rslookup.update


fengshui_1998


 
No, there is nothing to select. It starts out with an empty set of records for the particular ID and rewrites them from the form submission. That is, it first deletes the entries for that ID, which is not an autonumber field and for which there are multiple entries with the same one and all are removed first. The purpose is to recreate a set of records and to be sure that the old set is completely removed before doing so.

The checkbox form field is sending a "value=" of 1 and a "name=" of the ID number (it's created by looping through the same lookup table) if it's selected. If the Insert loop receives a "1", it compares the "name" with the ID value from the lookup table, runs the subroutine and writes the lookup tables ID to the table being edited. I tried to simplify the code and field names for the posting and somehow made it more confusing by ending up with two fields called "ID." The two ID fields actually have different names.

Anyway, this is working fine by itself but I am unsure how to add the second value, which is coming directly from the form's text field (one for each checkbox) in the form, and not from the lookup loop and they all have the same name of "fee."

Don Don
don@pc-homepage.com
Experienced in HTML, Perl, VBScript, PWS, IIS and Apache. Run OS/2 Warp 4, BeOS v5 and Windows NT/2000 (only when I have to!)
 
Except for some appearance tweeks, it is working now. What was wrong was something basic in the form itself. Each of the text fields had the same name (I missed it because it's part of a loop so I saw it only once), which was of course, confusing the script so I appended the record ID to each so that they would be different for each selction: "name=fee_" & ID Don
don@pc-homepage.com
Experienced in HTML, Perl, VBScript, PWS, IIS and Apache. Run OS/2 Warp 4, BeOS v5 and Windows NT/2000 (only when I have to!)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top