Creating a form with multi select
Creating a form with multi select
am 06.07.2007 16:29:38 von bcap
hi,
I am trying to create a form where you may have more than one person
at a meeting, but want to have them be related to the same meeting.
I have a mulitple select text area and if you select more than one,
all the records are being added to the same row. so if I picked the
following three people:
(Person ID/Desc)
1 - mickey mouse
2 - donald duck
3 - goofy
The row in the data base would look like this:
(Meeting ID/ Person ID)
1 - 1,2,3
But I would like to do this:
(Meeting ID/ Person ID)
1 - 1
1 - 2
1 - 3
I hope this makes sense, if it does does anyone have a suggest on how
to best do this?
Re: Creating a form with multi select
am 06.07.2007 19:05:55 von Jon Paal
you'll need to show us what your code attempt has been, then others can show possible fix.
> I hope this makes sense, if it does does anyone have a suggest on how
> to best do this?
>
Re: Creating a form with multi select
am 06.07.2007 23:12:14 von bcap
Hi,
Thank you, below is my code.
The multiselect box is working fine. I just can't seem to find a way
to Add each selected as individuals in my AddNew/Update statament. Do
I need some kind of loop?
Re: Creating a form with multi select
am 07.07.2007 17:09:30 von Jon Paal
it can help to see the format of the selected values in a response.write statement. The multiple select should return comma
delimited values.
Split these and you will get an array. Use the array to create the SQL statement desired.
"bcap" wrote in message news:1183756334.499137.311480@k79g2000hse.googlegroups.com.. .
> Hi,
>
> Thank you, below is my code.
>
> The multiselect box is working fine. I just can't seem to find a way
> to Add each selected as individuals in my AddNew/Update statament. Do
> I need some kind of loop?
>
>
>
>
Re: Creating a form with multi select
am 09.07.2007 16:42:54 von bcap
Hi,
I have created the following array:
Dim getPID
getPID = request.form("PID")
for i = 0 to getPID
oRS3.AddNew
oRS3.Fields("PID")=(request.form("PID" & i))
oRS3.Update
Next
However I am getting this error message:
Microsoft VBScript runtime error '800a000d'
Type mismatch: '[string: "51, 69, 132, 112, 10"]'
Any thoughts? Thanks for all the help this far! =)
Kind Regards,
Ray
Re: Creating a form with multi select
am 09.07.2007 17:46:24 von bcap
Ok So I working the split. Here is what I have for code:
Dim MyString, MyArray
MyString = request.form("PID")
MyArray = Split(MyString,",") 'the delimiter is the comma
response.write MyArray
I am getting this error message:
Response object error 'ASP 0106 : 80020005'
Type Mismatch
An unhandled data type was encountered.
Thanks for you help, thoughts, and pateince.
Re: Creating a form with multi select
am 09.07.2007 21:14:32 von Jon Paal
you can't write an array you must loop through an array and write each element.
For i = 0 to UBound(MyArray )
response.write MyArray(i) & "
" & vbcrlf
Next
"bcap" wrote in message news:1183995984.194274.222550@o61g2000hsh.googlegroups.com.. .
> Ok So I working the split. Here is what I have for code:
>
> Dim MyString, MyArray
> MyString = request.form("PID")
> MyArray = Split(MyString,",") 'the delimiter is the comma
>
> response.write MyArray
>
>
> I am getting this error message:
>
> Response object error 'ASP 0106 : 80020005'
> Type Mismatch
> An unhandled data type was encountered.
>
> Thanks for you help, thoughts, and pateince.
>
>
>
Re: Creating a form with multi select
am 09.07.2007 22:07:38 von bcap
Hi,
Thank you very much. I am learning a lot I appecrciate the help.
I understadn that the Ubound will give the highest array member. When
I try to update my databse with the multiple records, it is only
updating with one record ( I believe this is becuase of the Ubound
fucntion).
How can I make sure all record get into my db?
Here is my curent code:
Dim MyString, MyArray
MyString = request.form("PID")
MyArray = Split(MyString,",") 'the delimiter is the comma
For i = 0 to UBound(MyArray)
oRS3.Fields("PID")= MyArray(i)
Next
oRS3.Update
Re: Creating a form with multi select
am 09.07.2007 22:35:52 von reb01501
bcap wrote:
> Hi,
>
> Thank you very much. I am learning a lot I appecrciate the help.
>
> I understadn that the Ubound will give the highest array member. When
> I try to update my databse with the multiple records, it is only
> updating with one record ( I believe this is becuase of the Ubound
> fucntion).
>
> How can I make sure all record get into my db?
>
> Here is my curent code:
>
> Dim MyString, MyArray
> MyString = request.form("PID")
> MyArray = Split(MyString,",") 'the delimiter is the comma
>
> For i = 0 to UBound(MyArray)
> oRS3.Fields("PID")= MyArray(i)
> Next
>
> oRS3.Update
Look at what your code is doing.
You are looping through the array, setting the value of the PID field in
the CURRENT record of the recordset to the ith value. No attempt to move
to the next record in the recordset (we don't even have any idea if your
recordset even contains multiple records), no attempt to add a new
record to the recordset ...
Then after the loop is finished, and PID field in the current record
contains the last value of the array, you call the Update method. So of
course, the current record in the database is updated with the last
value in the array.
Going back to your first post I see that you want to add a new record
for each PID. Instead of confusing everone by using the word "update"
(as in "... try to update my databse with the multiple records..."), you
should use the word "insert" or even "append". "Update" implies
modifying existing records.
I always try to discourage people from using recordsets to maintain
data, but since you have started ...
Dim MyString, MyArray
MyString = request.form("PID")
MyArray = Split(MyString,",") 'the delimiter is the comma
For i = 0 to UBound(MyArray)
oRS3.AddNew
oRS3.Fields("MeetingID") = 1
oRS3.Fields("PID")= MyArray(i)
oRS3.Update
Next
Better yet would be to use a sql statement to update your data:
Dim sql, cmd, arParms
sql="Insert Into tablename (MeetingID, PID) values (?,?)"
set cmd=createobject("adodb.command")
cmd.commandtype=1 'adCmdText
cmd.commandtext = sql
set cmd.activeconnection = yourconnectionobject
MyString = request.form("PID")
MyArray = Split(MyString,",") 'the delimiter is the comma
For i = 0 to UBound(MyArray)
arParms=Array(1, MyArray(i))
cmd.Execute ,arParms,128 '128=adExecuteNoRecords
Next
'close and destroy your connection if finished with it
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Re: Creating a form with multi select
am 11.07.2007 16:24:07 von bcap
thank you very much! =-)