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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

asp: type mismatch and update loop

Status
Not open for further replies.

selaine

Programmer
Oct 11, 2001
85
0
0
US
I actually have two issues/questions:

I have an autonumber field in an access db table that I grab and later use to update a record in another table withing the same db.

The code I use to get it from the db table is:
'Retrieve the Registration Identification Number
strRegisterID = Rs("Register_ID")

Prior to testing my code and actually updating the db, I'm trying to write it to the page to make sure their isn't a loop or massive problem with my code.

I'm writing to the page like this:

for each objItem in request.Form()
if left(objItem,5)=&quot;cksub&quot; and request.Form(objItem) <> &quot;&quot; then
response.write(&quot;strRegisterID = &quot;)
response.write(strRegisterID)
tempsub=request.form(objItem)
response.write(&quot;tempsub = &quot;)
response.write(tempsub)
end if
tempsub = &quot;&quot;
next

When I do this, I'm getting a type mismatch error.
Question 1: Is this because I'm in the &quot;for each objItem&quot; loop that doesn't want to use the strRegisterID?

* * * * * * * * * * * * * * * * * * * * * * * * * * *
My next issue is updating two separate tables within the same database using two recordsets. I've created the following code for the update and want to know if anyone can tell if I'm on track or if my code is wacko. The end result is taking information from a form and placing it in my db as so:

All of the text fields and one checkbox called enotify are needed for my WebRegister table. But, all Checkbox selections starting with the value &quot;cksub&quot; and <> &quot;&quot; will be sent to another table. (Note: the checkboxes were generated dynamically and there may be more than one set of checkboxes on the page because user needs to be able to select one or all of them per set) Anyway, my code is as follows:

<%
'Grab variables from the querystring and remove any apostrophes
FormCompany=Request.Form(&quot;txtCompany&quot;)
strCompany=Replace(FormCompany, &quot;'&quot;, &quot;&quot;)

FormAddress=Request.Form(&quot;txtAddress&quot;)
strAddress=Replace(FormAddress, &quot;'&quot;, &quot;&quot;)

FormCity=Request.Form(&quot;txtCity&quot;)
strCity=Replace(FormCity, &quot;'&quot;, &quot;&quot;)

strState=Request.Form(&quot;txtState&quot;)
strZip=Request.Form(&quot;txtZip&quot;)
strPhone=Request.Form(&quot;txtPhone&quot;)
strFax=Request.Form(&quot;txtFax&quot;)

FormWebsite=Request.Form(&quot;txtWebsite&quot;)
strWebsite=Replace(FormWebsite, &quot;'&quot;, &quot;&quot;)

FormContact=Request.Form(&quot;txtContact&quot;)
strContact=Replace(FormContact, &quot;'&quot;, &quot;&quot;)

strCPhone=Request.Form(&quot;txtCPhone&quot;)

FormEmail=Request.Form(&quot;txtEmail&quot;)
strEmail=Replace(FormEmail, &quot;'&quot;, &quot;&quot;)


If Request.Form(&quot;txtnotify&quot;) = &quot;-1&quot; Then
FormNotify=Request.Form(&quot;txtnotify&quot;)
strNotify = &quot;You have chosen to receive automatic e-mail notification &quot;
strNotify = strNotify & &quot;when goods and/or services you indicated, come up for bid.&quot;
Else
FormNotify = &quot;0&quot;
strNotify = &quot;You will not be notified when goods and/or services you indicated &quot;
strNotify = strNotify & &quot;come up for bid&quot;
End If

strhidDate=Request.Form(&quot;txtDate&quot;)

'Create the statement to add a new record into the table &quot;WebRegister&quot;.
'The first parenthesis set defines the field names as defined in the table and the second set
'of parenthesis places the values as assigned above (taken from the user input of the form
'on the Supplier_Reg.asp page) into the described fields of the table. The replace function
'[example: replace(strCompany, &quot;'&quot;, &quot;&quot;)] removes any apostrophes the user may have entered
'(which causes code problems) before inserting the data into the records. The replace
'function should be used whenever a user is free to key in data of their choosing.

'Create a RecordSet object
Set SupRs = Server.CreateObject(&quot;ADODB.RecordSet&quot;) 'Create Supplier/Contact Info Recordset
Set ComRs = Server.CreateObject(&quot;ADODB.RecordSet&quot;) 'Create Commodities Info Recordset

'Open the table
strProvider=&quot;Provider=MSDASQL.1;Persist Security Info=False;Data Source=Register&quot;
SupRs.Open &quot;WebRegister&quot;, strProvider, adOpenKeySet, adLockPessimistic

'Add a new record to WebRegister Table
SupRs.AddNew
SupRs(&quot;Company_Name&quot;) = strCompany
SupRs(&quot;St_Address&quot;) = strAddress
SupRs(&quot;City&quot;) = strState
SupRs(&quot;Zip&quot;) = strZip
SupRs(&quot;Phone_Num&quot;) = strPhone
SupRs(&quot;Fax_Num&quot;) = strFax
SupRs(&quot;Web_Site&quot;) = strWebsite
SupRs(&quot;Contact_Person&quot;) = strContact
SupRs(&quot;Contact_Phone&quot;) = strCPhone
SupRs(&quot;Contact_Email&quot;) = strEmail
SupRs(&quot;Respond_Da&quot;) = strhidDate
SupRs(&quot;E_Notify&quot;)= FormNotify

'Update the record
SupRs.Update

'Retrieve the Registration Identification Number
strRegisterID = Rs(&quot;Register_ID&quot;)

'Close the recordset
SupRs.Close
Set SupRs = Nothing

ComRs.Open &quot;WebCommodities&quot;, strProvider, adOpenKeySet, adLockPessimistic

'Add a new record(s) to WebCommodities Table
'Need RegisterID for each checkbox selected
for each objItem in request.Form()
if left(objItem,5)=&quot;cksub&quot; and request.Form(objItem) <> &quot;&quot; then
ComRs.AddNew
ComRs(&quot;Register_ID&quot;) = strRegisterID
ComRs(&quot;SubCategory&quot;) = request.form(objItem)
ComRs.Update
next

'Close the recordset
ComRs.Close
Set ComRs = Nothing
%>

As far as my second issue is concerned, I'm not real confident that the For...Next loop to add the record(s) to the WebCommodities table is going to do the trick. There is other code on the page, but I believe its immaterial to my issues. I'd really appreciate any help on this!!
 
well lets deal with issue one (i havent gone through the other one)
instead of this:
for each objItem in request.Form()
if left(objItem,5)=&quot;cksub&quot; and request.Form(objItem) <> &quot;&quot; then
response.write(&quot;strRegisterID = &quot;)
response.write(strRegisterID)
tempsub=request.form(objItem)
response.write(&quot;tempsub = &quot;)
response.write(tempsub)
end if
tempsub = &quot;&quot;
next

try a simpler one:
for each objItem in request.Form()
response.write (objItem)
next

the type mismatch error maybe because objItem may not be a string...

and can i know what u r trying to ahieve using that loop?


Known is handfull, Unknown is worldfull
 
Prior to testing my code and actually updating the db, I'm trying to write it to the page to make sure their isn't a loop or massive problem with my code.

The second issue that I stated (my loop to actually add the info to the database will replace the code in issue one) - sounds redundant, but I'm just learning and am trying to debug by writing the values to the page.

I need to update two separate tables within the same database using two recordsets, which I've never done before. I've created the following code for the update and want to know if anyone can tell if I'm on track or if my code is wacko. The end result is taking information from a form and placing it in my db as so:

All of the text fields and one checkbox called enotify are needed for my WebRegister table. But, all Checkbox selections starting with the value &quot;cksub&quot; and <> &quot;&quot; will be sent to the WebCommodities table, along with the key field (which is retreived from the WebRegister table after adding the record to it, and since its an autonumber field and I need it to be inserted into the WebCommodities table to identify the user, I have to add the record to the WebRegister table before I can retrieve it to insert it into the WebCommodities table. (Note: the checkboxes were generated dynamically and there may be more than one set of checkboxes on the page because user needs to be able to select one or all of them per set)

The purpose of the WebCommodities table is to keep track of all items selected by the user that registered so they I know what commodities they sell, so that when our office goes out for bid for a certain item, we know which registrant to contact. The contact info goes to the WebRegister table, with the detailed records going to the WebCommodities table. The WebCommodities table has three fields: the keyid (autonumber field); the Register_ID field which will tie the items to the registrant(user); and the SubCategory field which is the item that they can provide to us. There may be one or 30 (don't know til I go thru checkboxes) items the indicate they can provide.

Hopefully, that explains things. Thanks for your interest in my question....This is a project that I've been working on since late March and involves a lot more than just this piece, but once I figure this piece out..... I'LL BE DONE!!!! and I'm just screaming to finish this project!! I really appreciate any help!!! Thanks!
 
hi,
if it validation that u r trying to do then the best way is to use javascript. why?
1. Its on the client side.
2. Beacuse of that ur server requests are reduced. ie any body who has not entered any or all of the data cannot submit the form to the server for processing if u use javascript. therefore the number of requests to the server reduces.

and ur second problem is pretty simple once u use javascript. since the form will have all the values needed u need not do any validation in ur ASP code at all...

Known is handfull, Unknown is worldfull
 
I'm not validating (that code is already done) With issue number one, I'm just debugging, so I'm writing info to my page rather than coding it on the page, to make sure I'm getting the information I need. The code I'm hoping to replace it with is actually issue two. So, issue one would be immaterial, if I knew my loop to update my second recordset was ok (I've never worked with more than one recordset and I'm learning all of this as I go) and I'm not sure if I coded it correctly. All of the text fields and one checkbox called enotify are needed for my WebRegister table. But, all Checkbox selections starting with the value &quot;cksub&quot; and <> &quot;&quot; will be sent to the WebCommodities table, along with the key field (which is retreived from the WebRegister table after adding the record to it, and since its an autonumber field and I need it to be inserted into the WebCommodities table to identify the user, I have to add the record first. (Note: the checkboxes were generated dynamically and there may be more than one set of checkboxes on the page because user needs to be able to select one or all of them per set)

Anyway, this is the section I'm worried about.....

ComRs.Open &quot;WebCommodities&quot;, strProvider, adOpenKeySet, adLockPessimistic

'Add a new record(s) to WebCommodities Table
'Need RegisterID for each checkbox selected
for each objItem in request.Form()
if left(objItem,5)=&quot;cksub&quot; and request.Form(objItem) <> &quot;&quot; then
ComRs.AddNew
ComRs(&quot;Register_ID&quot;) = strRegisterID
ComRs(&quot;SubCategory&quot;) = request.form(objItem)
ComRs.Update
next

'Close the recordset
ComRs.Close
Set ComRs = Nothing


Would really appreciate input on this!! Thanks!!!
 
well,
i also dont find any problem with ur code. so lets start debugging it. first try m simple for each loop. with that we can be sure whether the valuse of the checkboxes are really picked...

Known is handfull, Unknown is worldfull
 
Maybe I haven't had enough coffee today, but what do you mean &quot;try M simple for each loop&quot;?
 
oops its:
&quot;try My simple for each loop&quot;:
this one:
for each objItem in request.Form()
response.write (objItem)
next

if this is working then we can go to the next step...


Known is handfull, Unknown is worldfull
 
Prior to trying your idea, which I'll do after I solve this problem.....

In my first post, I show a line where I get the Register_ID from the table and assign it to the variable strRegisterID. When I try doing a response.write of the variable, I get this error:

Microsoft VBScript runtime error '800a000d'
Type mismatch
/Government/Purchasing/add_supplier.asp, line 121

which is this line in the code:
strRegisterID = Rs(&quot;Register_ID&quot;)

In my WebRegister table, the Register_ID (key) is a numeric field of type autonumber (which in design view shows it as a long integer). In my WebCommodities table I also have that field defined as a type &quot;long integer&quot;. So, how would I get the Register_ID value after updating and assign it to a variable I can use with response.write, and then be able to place the Register_ID field into the WebCommodities table. This is something I haven't dealt with before. Any ideas?

I went ahead and removed that line temporarily to try your simple loop and this is the results that showed up:

txtCompanytxtCPhonetxtAddresstxtZiptxtCitycksub4400txtStatetxtWebsitetxtDatetxtPhonetxtFaxcksub4200txtContacttxtNotifytxtEmail


If you viewed them as separated they would look like this:
txtCompany txtCPhone
txtAddress txtZip
txtCity cksub4400
txtState txtWebsite
txtDate txtPhone
txtFax cksub4400
txtContact txtNotify
txtEmail

(Note: cksub4200 and cksub4400 if placed in an array with their values, would be something like this:
ckboxarray(4201,4202,4204,4208,4401,4402,4403,4404)
 
Whoops - forget type mismatch error on line 121 I should've had:

strRegisterID = SupRs(&quot;Register_ID&quot;)
 
First of all, I've solved issue number 1: My first recordset was defined as SupRs. So, when it got to the following code, it came up with a type mismatch error:

'Retrieve the Registration Identification Number
strRegisterID = Rs(&quot;Register_ID&quot;)

The line above should've been:
strRegisterID = SupRs(&quot;Register_ID&quot;)

So, that problem is solved.

Regarding issue number two:
I think I did a poor job of explaining my true issue, so I'm re-explaining...

In the WebCommodities table, I need to insert a new record for each checkbox checked - I created the following code to check my values (keep in mind that the number of elements in the array and its values will be different each time)

CkBoxArray=&quot;(&quot;
for each objItem in request.Form()
if left(objItem,5)=&quot;cksub&quot; and request.Form(objItem) <> &quot;&quot; then
CkBoxArray=CkBoxArray & request.Form(objItem) & &quot;,&quot;
end if
next
theLen=len(CkBoxArray)
CkBoxArray=left(CkBoxArray,theLen-1)
CkBoxArray=CkBoxArray & &quot;)&quot;
response.Write(&quot;Checkboxes with value of cksub plus categoryid concatenated = &quot; & CkBoxArray & &quot;<br>&quot;)

Based on the above code, this is the output:

Checkboxes with value of cksub plus categoryid concatenated = (4401, 4402, 4403,4202, 4203, 4204, 4205, 4208)

So, in this instance I'd need to insert 8 new records, each with the same registerid - so if I were to display those 8 records from my access table after they were inserted, I'd have this

Table: WebCommodities
Fields: WebRecID (autonumber), RegisterID, SubCategory

1 10 4401
2 10 4402
3 10 4403
4 10 4202
5 10 4203
6 10 4204
7 10 4205
8 10 4208

So, basically what I need to figure out is how to loop thru my checkbox array and insert a record for each value with the same Register ID. Hopefully, this explains things more directly. Based on this scenario, I don't think my loop will work.......Thanks!!
 
To clarify, &quot;....I need to figure out is how to loop thru my checkbox array and insert a record for each value with the same Register ID.&quot;

Based on the above scenario, the registerID which I received from my first recordset (for this form submission)is equal to 10. Each elecment in the array will use the same registerid when the record is inserted into the table.
 
Still hoping for a solution on this post. Thanks!
 
o.k i think i have it now. but first can u tell me how u create the checkboxes in the previos page? are they dynamic or are they hardcoded?

Known is handfull, Unknown is worldfull
 
Your code should work since you get the right values in the CkBoxArray test array
Code:
for each objItem in request.Form() 
    if left(objItem,5)=&quot;cksub&quot; and request.Form(objItem) <> &quot;&quot; then
        ComRs.AddNew
        ComRs(&quot;Register_ID&quot;) = strRegisterID
        ComRs(&quot;SubCategory&quot;) = request.form(objItem)
        ComRs.Update
    end if    
next

________
George, M
 
To answer your question vbkris, the checkboxes on the first page are hardcoded (even though I could've created them dynamically). It's the checkboxes on the 2nd page that generate the checkboxes dynamically, via my access db (it just made more sense and used less code).

shaddow - I tried this code:
for each objItem in request.Form()
if left(objItem,5)=&quot;cksub&quot; and request.Form(objItem) <> &quot;&quot; then
ComRs.AddNew
ComRs(&quot;Register_ID&quot;) = strRegisterID
ComRs(&quot;SubCategory&quot;) = request.form(objItem)
ComRs.Update
end if
next

and I get this error

Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E21)
Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.
/Government/Purchasing/add_supplier.asp, line 157


line 157 is
ComRs(&quot;SubCategory&quot;) = request.form(objItem)

To help someone help me, here's the entrie code for this page, excluding formatting. (Note: some is temporary for debugging purposes)

<!-- #include file=&quot;adovbs.inc&quot; -->

<%
'Declare variables

Dim FormCompany
Dim strCompany
Dim FormAddress
Dim strAddress
Dim FormCity
Dim strCity
Dim strState
Dim strZip
Dim strPhone
Dim strFax
Dim FormWebsite
Dim strWebsite
Dim FormContact
Dim strContact
Dim strCPhone
Dim FormEmail
Dim strEmail
Dim strhidDate
Dim FormNotify
Dim strNotify
Dim Rs
Dim strRegisterID
Dim varRegisterID
Dim strProvider
Dim Count
Count = 0

'When the CkBoxArray is created and then displayed, using the code below, it basically looks something like this:
' [sample only]: CkBoxArray = (4401, 4402, 4403, 4404, 4201, 4202, 4203, 4204)

CkBoxArray=&quot;(&quot;
for each objItem in request.Form()
if left(objItem,5)=&quot;cksub&quot; and request.Form(objItem) <> &quot;&quot; then
CkBoxArray=CkBoxArray & request.Form(objItem) & &quot;,&quot;
end if
next
theLen=len(CkBoxArray)
CkBoxArray=left(CkBoxArray,theLen-1)
CkBoxArray=CkBoxArray & &quot;)&quot;
response.Write(&quot;Checkboxes with value of cksub plus categoryid concatenated = &quot; & CkBoxArray & &quot;<br>&quot;)

'Grab variables from the querystring and remove any apostrophes
FormCompany=Request.Form(&quot;txtCompany&quot;)
strCompany=Replace(FormCompany, &quot;'&quot;, &quot;&quot;)

FormAddress=Request.Form(&quot;txtAddress&quot;)
strAddress=Replace(FormAddress, &quot;'&quot;, &quot;&quot;)

FormCity=Request.Form(&quot;txtCity&quot;)
strCity=Replace(FormCity, &quot;'&quot;, &quot;&quot;)

strState=Request.Form(&quot;txtState&quot;)
strZip=Request.Form(&quot;txtZip&quot;)
strPhone=Request.Form(&quot;txtPhone&quot;)
strFax=Request.Form(&quot;txtFax&quot;)

FormWebsite=Request.Form(&quot;txtWebsite&quot;)
strWebsite=Replace(FormWebsite, &quot;'&quot;, &quot;&quot;)

FormContact=Request.Form(&quot;txtContact&quot;)
strContact=Replace(FormContact, &quot;'&quot;, &quot;&quot;)

strCPhone=Request.Form(&quot;txtCPhone&quot;)

FormEmail=Request.Form(&quot;txtEmail&quot;)
strEmail=Replace(FormEmail, &quot;'&quot;, &quot;&quot;)


If Request.Form(&quot;txtnotify&quot;) = &quot;-1&quot; Then
FormNotify=Request.Form(&quot;txtnotify&quot;)
strNotify = &quot;You have chosen to receive automatic e-mail notification &quot;
strNotify = strNotify & &quot;when goods and/or services you indicated, come up for bid.&quot;
Else
FormNotify = &quot;0&quot;
strNotify = &quot;You will not be notified when goods and/or services you indicated &quot;
strNotify = strNotify & &quot;come up for bid&quot;
End If

strhidDate=Request.Form(&quot;txtDate&quot;)

'Create the statement to add a new record into the table &quot;WebRegister&quot;.
'The first parenthesis set defines the field names as defined in the table and the second set
'of parenthesis places the values as assigned above (taken from the user input of the form
'on the Supplier_Reg.asp page) into the described fields of the table. The replace function
'[example: replace(strCompany, &quot;'&quot;, &quot;&quot;)] removes any apostrophes the user may have entered
'(which causes code problems) before inserting the data into the records. The replace
'function should be used whenever a user is free to key in data of their choosing.

'Create a RecordSet object
Set SupRs = Server.CreateObject(&quot;ADODB.RecordSet&quot;) 'Create Supplier/Contact Info Recordset
Set ComRs = Server.CreateObject(&quot;ADODB.RecordSet&quot;) 'Create Commodities Info Recordset

'Open the table
strProvider=&quot;Provider=MSDASQL.1;Persist Security Info=False;Data Source=Register&quot;
SupRs.Open &quot;WebRegister&quot;, strProvider, adOpenKeySet, adLockPessimistic

'Add a new record
SupRs.AddNew
SupRs(&quot;Company_Name&quot;) = strCompany
SupRs(&quot;St_Address&quot;) = strAddress
SupRs(&quot;City&quot;) = strCity
SupRs(&quot;State&quot;) = strState
SupRs(&quot;Zip&quot;) = strZip
SupRs(&quot;Phone_Num&quot;) = strPhone
SupRs(&quot;Fax_Num&quot;) = strFax
SupRs(&quot;Web_Site&quot;) = strWebsite
SupRs(&quot;Contact_Person&quot;) = strContact
SupRs(&quot;Contact_Phone&quot;) = strCPhone
SupRs(&quot;Contact_Email&quot;) = strEmail
SupRs(&quot;Respond_Da&quot;) = strhidDate
SupRs(&quot;E_Notify&quot;)= FormNotify

'Update the record
SupRs.Update

'Retrieve the Registration Identification Number
strRegisterID = SupRs(&quot;Register_ID&quot;)

'Close the recordset
SupRs.Close
Set SupRs = Nothing

ComRs.Open &quot;WebCommodities&quot;, strProvider, adOpenKeySet, adLockPessimistic

for each objItem in request.Form()
if left(objItem,5)=&quot;cksub&quot; and request.Form(objItem) <> &quot;&quot; then
ComRs.AddNew
ComRs(&quot;Register_ID&quot;) = strRegisterID
ComRs(&quot;SubCategory&quot;) = request.form(objItem)
ComRs.Update
end if
next

'Close the recordset
ComRs.Close
Set ComRs = Nothing

%>

<html>
<head>
<title>Rock Island County - Supplier Registration Page 2</title>
</head>
<body>

<center>Purchasing Department</center>
<center>- Please select from the following list: -</center>
<% Response.Write(strCompany) %>
<% Response.Write &quot;<br>&quot; %>
<% Response.Write &quot;Thank you for registering!&quot; %>
<% Response.Write &quot;<br>&quot; %>
<% Response.Write &quot;Your Supplier Identification Number is: W-&quot; %>
<% Response.Write(strRegisterID) %>
<% Response.Write &quot;<br>&quot; %>
<% Response.Write &quot;strNotify = &quot; %>
<% Response.Write(strNotify) %>
<% Response.Write &quot;<br>&quot; %>
<% Response.Write(Count) %>
<% Response.Write &quot;You have now been added to our Supplier Database. We appreciate your time and effort in completing the Supplier Registration Form.&quot; %>
<% Response.Write &quot;Thank you!&quot; %>

</body>
</html>
 
Ok, I'm narrowing down the problem. I've commented out this code:

'for each objItem in request.Form()
' if left(objItem,5)=&quot;cksub&quot; and request.Form(objItem) <> &quot;&quot; then
' ComRs.AddNew
' ComRs(&quot;Register_ID&quot;) = strRegisterID
' ComRs(&quot;SubCategory&quot;) = request.form(objItem)
' ComRs.Update
' end if
'next

and replaced it with this:

for each objItem in request.Form()
if left(objItem,5)=&quot;cksub&quot; and request.Form(objItem) <> &quot;&quot; then
ComRs.AddNew
'<debug>
response.write &quot;Adding new record for objitem: &quot; & objitem & &quot;<br>&quot;
'</debug>
ComRs(&quot;Register_ID&quot;) = strRegisterID
'<debug>
response.write &quot;Added field strRegisterID with a value of: &quot; & strRegisterID & &quot;<br>&quot;
'</debug>
ComRs(&quot;SubCategory&quot;) = request.form(objItem)
'<debug>
response.write &quot;SubCategory Updated with a value of: &quot; & request.form(objitem) & &quot;<br>&quot;
'</debug>
ComRs.Update
'<debug>
response.write &quot;Update Success!&quot;
'</debug>
end if
next

I think my problem is that I need to loop thru the CkBoxArray to insert the SubCategory values into the db, because I got the same error with this until I tried a little experiment:

I opened up page one, keyed in data and only selected one main category (Office Equipment). Then on page two, I only selected one checkbox from the Office Equipment list of checkboxes and everything worked. The response.write version produced this on the final page:

Checkboxes with value of cksub plus categoryid concatenated = (4202)
Adding new record for objitem: cksub4200
Added field strRegisterID with a value of: 4
SubCategory Updated with a value of: 4202

Update Success!

So, I think that if I select more than one, its trying to place the entire array of values into the subcategory field (which is only 4 characters)

So, I think I need to change this code:

for each objItem in request.Form()
if left(objItem,5)=&quot;cksub&quot; and request.Form(objItem) <> &quot;&quot; then
ComRs.AddNew
ComRs(&quot;Register_ID&quot;) = strRegisterID
ComRs(&quot;SubCategory&quot;) = request.form(objItem)
ComRs.Update
end if
next

So that
ComRs(&quot;SubCategory&quot;) = request.form(objItem)
is actually using the array element. But, I need to keep in mind that the number of elements will vary.

If I select two main categories on the first page (say: Office Equipment and Office Supplies)

and select the checkboxes with values of 4201, 4202, 4203, and 4204 from Office Equipment subcategory list

and select the checkboxes with values of 4401, 4402, 4403, and 4404 from the Office Supplies subcategory list, then my array contains this:

CkBoxArray = (4401, 4402, 4403, 4404, 4201, 4202, 4203, 4204)

So basically the loop I have is trying to insert
4401, 4402, 4403, 4404, 4201, 4202, 4203, 4204 into a four character field.

Error 0x80040E21 is said to be caused when you try to insert too much data into a specified field, for example if you enter a string that is 20 characters lone into a field that is defined as 4 characters. So now that I've narrowed down the problem, can anyone help me fix my loop so that the registerID for each record inserted remains the same, but the subcategory is using 1 element at a time from the array? Thanks!!!!!
 
first of all u said register_id is generated by the database, so it will be impossible to set it notmally.

Code:
if left(objItem,5)=&quot;cksub&quot; and request.Form(objItem) <> &quot;&quot; then
ComRs.AddNew
ComRs(&quot;Register_ID&quot;) = strRegisterID
ComRs(&quot;SubCategory&quot;) = request.form(objItem)
ComRs.Update
end if 
next

in the code above strRegisterID is always empty because u dont need an id (as db is generating it). so first change that in the db...

or have i read something wrong?

Known is handfull, Unknown is worldfull
 
The Register_ID is the key (autonumber field) to another table (WebRegister) within the same access db. All of the basic user data from the form is inserted into this table with the first recordset. After I insert (add) the record to the WebRegister table, I grab the Register_ID and store it in a variable called strRegisterID. Then the first recordset is closed.

Then, I open a second recordset so that I can add the records pertaining to the WebCommodities table, based on the selections made by the user. The WebCommodities has its own key field (autonumber) which is automatically generated (incremented and created) when a record is added. So, basically I need to insert the RegisterID into each record, along with one of the subcategories at a time.

So, in the scenario I mentioned in my most recent posting, where the CkBoxArray = (4401, 4402, 4403, 4404, 4201, 4202, 4203, 4204) The contents of the table would end up looking something like this (lets assume the value of the strRegisterID is 5.

Table: WebCommodities
Fields: WebRecID (autonumber), RegisterID, SubCategory
(First column would be WebRecID - Second column is value from strRegisterID and Third Column is the individual elements from the CkBoxArray.

1 5 4401
2 5 4402
3 5 4403
4 5 4202
5 5 4203
6 5 4204
7 5 4205
8 5 4208

Hope that explains things better!
 
Is this code working ok?
Cuz i see in your whole code same 2 loops with diferent results.
Also you dont try to add more then the value of an checkbox cuz you used Request.Form(objItem)
The problem is that you might have more then 1 checkbox with same name, and so it will come at server with more then 4 characters.
First test only this code and see if the array it's ok but dont comma separate, use diferent separator. If i'm right you should see some comma there to.
Code:
CkBoxArray=&quot;(&quot;
for each objItem in request.Form() 
    if left(objItem,5)=&quot;cksub&quot; and request.Form(objItem) <> &quot;&quot; then
    CkBoxArray=CkBoxArray & request.Form(objItem) & &quot;:&quot;
    end if    
next
    theLen=len(CkBoxArray)
    CkBoxArray=left(CkBoxArray,theLen-1)
    CkBoxArray=CkBoxArray & &quot;)&quot;
    response.Write(&quot;Checkboxes with value of cksub plus categoryid concatenated = &quot; & CkBoxArray & &quot;<br>&quot;)

Test this code.

________
George, M
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top