470,648 Members | 1,564 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,648 developers. It's quick & easy.

split question, I guess

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.


Jul 19 '05 #1
2 2106

"middletree" <mi********@htomail.com> wrote in message
news:up**************@TK2MSFTNGP10.phx.gbl...
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
Jul 19 '05 #2
WOW! Very helpful tips. Thanks!
"Ray at <%=sLocation%>" <myFirstNameATlane34dotKOMM> wrote in message
news:#X*************@tk2msftngp13.phx.gbl...

"middletree" <mi********@htomail.com> wrote in message
news:up**************@TK2MSFTNGP10.phx.gbl...
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

Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Will McGugan | last post: by
8 posts views Thread by uc_sk | last post: by
9 posts views Thread by martin | last post: by
7 posts views Thread by Mark A | last post: by
cwoozy
3 posts views Thread by cwoozy | last post: by
1 post views Thread by Korara | last post: by
reply views Thread by warner | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.