Current location: Hot Scripts Forums » Programming Languages » ASP » type mismatch and update loop - HELP!


type mismatch and update loop - HELP!

Reply
  #1 (permalink)  
Old 09-19-03, 09:05 PM
seala seala is offline
Newbie Coder
 
Join Date: Aug 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation type mismatch and update loop - HELP!

I could've sworn I posted this yesterday, but when I looked I didn't see it, so if this is a duplicate posting, I apologize.

I actually have two issues/questions:

Issue 1:
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)="cksub" and request.Form(objItem) <> "" then
response.write("strRegisterID = ")
response.write(strRegisterID)
tempsub=request.form(objItem)
response.write("tempsub = ")
response.write(tempsub)
end if
tempsub = ""
next

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

* * * * * * * * * * * * * * * * * * * * * * * * * * *
Issue 2:
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 "cksub" and <> "" 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, my code is as follows:

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

FormAddress=Request.Form("txtAddress")
strAddress=Replace(FormAddress, "'", "")

FormCity=Request.Form("txtCity")
strCity=Replace(FormCity, "'", "")

strState=Request.Form("txtState")
strZip=Request.Form("txtZip")
strPhone=Request.Form("txtPhone")
strFax=Request.Form("txtFax")

FormWebsite=Request.Form("txtWebsite")
strWebsite=Replace(FormWebsite, "'", "")

FormContact=Request.Form("txtContact")
strContact=Replace(FormContact, "'", "")

strCPhone=Request.Form("txtCPhone")

FormEmail=Request.Form("txtEmail")
strEmail=Replace(FormEmail, "'", "")


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

strhidDate=Request.Form("txtDate")

'Create the statement to add a new record into the table "WebRegister".
'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, "'", "")] 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("ADODB.RecordSet") 'Create Supplier/Contact Info Recordset
Set ComRs = Server.CreateObject("ADODB.RecordSet") 'Create Commodities Info Recordset

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

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

'Update the record
SupRs.Update

'Retrieve the Registration Identification Number
strRegisterID = Rs("Register_ID")

'Close the first recordset
SupRs.Close
Set SupRs = Nothing

'Open the next recordset
ComRs.Open "WebCommodities", 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)="cksub" and request.Form(objItem) <> "" then
ComRs.AddNew
ComRs("Register_ID") = strRegisterID
ComRs("SubCategory") = request.form(objItem)
ComRs.Update
next

'Close the second 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!!
Reply With Quote
  #2 (permalink)  
Old 09-22-03, 05:27 PM
seala seala is offline
Newbie Coder
 
Join Date: Aug 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation create new rec in db for each val in array?

Second Posting to
asp: type mismatch and update loop

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("Register_ID")

The line above should've been:
strRegisterID = SupRs("Register_ID")

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

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!!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 03:35 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.