469,352 Members | 1,797 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

asp: type mismatch and update loop

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

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?

* * * * * * * * * * * * * * * * * * * * * * * * * * *
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 "cksub" and <> "" 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
strCompany=Replace(FormCompany, "''", "")

strAddress=Replace(FormAddress, "''", "")

strCity=Replace(FormCity, "''", "")


strWebsite=Replace(FormWebsite, "''", "")

strContact=Replace(FormContact, "''", "")


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


''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("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

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

''Close the recordset
Set SupRs = Nothing

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("Register_ID") = strRegisterID
ComRs("SubCategory") = request.form(objItem)

''Close the recordset
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!!

This message is posted by http://Asp.ForumsZone.com

Jul 19 '05 #1
0 2550

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Jake | last post: by
1 post views Thread by Mark | last post: by
5 posts views Thread by junglist | last post: by
34 posts views Thread by clinttoris | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.