split question, I guess

M

middletree

Not really sure what the problem is, perhaps I am using split wrong.

Page should get form fields form previous page and some of them will go into
a tabel called Personal. Other items, to resolve a many-to-many
relationship, will go into a table called PersonalPeople, which consists of
2 fields: the PK's from the People table and the Perosnal table. I decided
to have the 30 or so checkboxes on the first page all have the same name, as
they are built dynamcially from the People table. If you check boxes
numbered 1, 6, and 19, then request.form("People") returns a string of
(1,6,19)

All of the above has been confirmed to work using Response.write.

Now, I want to pull each value from the above comma-delimted string and
insert them into the PersonalPeople table. I had already obtained the
PersonalID (the PK of the Personal Table). so I built a loop which would
take the values out of the comma-delimted string, and insert them along with
the PersonalID

Can't seem to make it work. I've spent way too many hours on this one
problem. Any help would be appreciated. Here's the code that's relevant,
with a couple of quick comments at the end. This code is from the 2nd page,
the one that is after the form is submitted.
:

--------------------------
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Inetpub\wwwroot\Grace\Shape.mdb;User Id=admin;Password=;"

Set objConnection = Server.CreateObject("ADODB.Connection")
objConnection.ConnectionString = strConnection
objConnection.Open

'this is the stuff that goes into personal table, but also need to add
things in
'combo tables, like gift, people, area,

strSQL = "INSERT INTO Personal[blah,blah,blah]
strSQL = strSQL & "VALUES [blah,blah,blah]
objConnection.Execute strSQL

'get the PersonalID (PK) that was just inserted
set rs = objConnection.execute("select MAX(PersonalID) from Personal")
'response.write "New ID was " & rs(0)
strPersonalID = rs(0)

objConnection.Close
Set objConnection = nothing

'these three will pull from the checkboxes, should give a string
Set objConnection = Server.CreateObject("ADODB.Connection")
objConnection.ConnectionString = strConnection
objConnection.Open

strPeopleID = request.form("People")
if len(strPeopleID)>0 then
arrPeople = SPLIT(strPeople,",")
for x=lbound(arrPeople) to ubound(arrPeople)
strSQL = "INSERT into PersonalPeople(PersonalID,PeopleID) "
strSQL = strSQL & "VALUES('"&strPersonalID&"','"&strPeopleID&"')"
response.write strSQL
response.end
objConnection.Execute strSQL
next
end if

===================================

Thing is, I put a response.write after that --if len(strPeopleID)>0 then--
line, and it became apparent that I was, in fact, falling into the IF
statement correctly. But for some reason, the next response.write doesn't
yield anything. So I guess I am doing the split thing wrong. I tried doing a
response.write arrPeople, but it threw an error. So I can't see where I am
going wrong.

Please help. I'll be glad to send complete code if asked.
 
R

Ray at

set rs = objConnection.execute("select MAX(PersonalID) from Personal")
'response.write "New ID was " & rs(0)
strPersonalID = rs(0)

objConnection.Close
Set objConnection = nothing

'these three will pull from the checkboxes, should give a string
Set objConnection = Server.CreateObject("ADODB.Connection")
objConnection.ConnectionString = strConnection
objConnection.Open

strPeopleID = request.form("People")
if len(strPeopleID)>0 then
arrPeople = SPLIT(strPeople,",")
for x=lbound(arrPeople) to ubound(arrPeople)
strSQL = "INSERT into PersonalPeople(PersonalID,PeopleID) "
strSQL = strSQL & "VALUES('"&strPersonalID&"','"&strPeopleID&"')"


I think you'd want to insert arrPeople(x) there instead of strPeopleID.
strPeopleID will equal something like "2, 3, 6, 8, 32, 49"

Also, when you Split() strPeopleID, split by ", " instead of "," or
replace(strPeopleID, ", ", ",") before splitting. There are spaces after
the commas.

Also, is PeopleID a text type column? You have it delimited with '.

Another thing is that you should put spaces after (at least) the &
concatenation operator. If you don't, you'll run into issues if you have a
variable name that starts with an "h" as &h indicates a hex value is to
follow.

Ray at home
 
M

middletree

WOW! Very helpful tips. Thanks!


Ray at said:
I think you'd want to insert arrPeople(x) there instead of strPeopleID.
strPeopleID will equal something like "2, 3, 6, 8, 32, 49"

Also, when you Split() strPeopleID, split by ", " instead of "," or
replace(strPeopleID, ", ", ",") before splitting. There are spaces after
the commas.

Also, is PeopleID a text type column? You have it delimited with '.

Another thing is that you should put spaces after (at least) the &
concatenation operator. If you don't, you'll run into issues if you have a
variable name that starts with an "h" as &h indicates a hex value is to
follow.

Ray at home
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top