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

insert Currency or number - from Session

Status
Not open for further replies.

schase

Technical User
Sep 7, 2001
1,756
US
Hi all,

I have one form, upon submit, values go into sessions.

then on a page they insert with the below code, but if my access 2000 database is set to have the data as numeric or currency, I get a type mismatch error.

Any ideas?

Thank you


<%
rs.addnew
rs(&quot;StockNum&quot;)= Session(&quot;txtStock&quot;)
rs(&quot;Year&quot;)=Session(&quot;txtYear&quot;)
rs(&quot;Make&quot;)=Session(&quot;txtMake&quot;)
rs(&quot;Model&quot;) =Session(&quot;strModel&quot;)
rs(&quot;Trim&quot;)=Session(&quot;txtTrim&quot;)
rs(&quot;Trans&quot;)=Session(&quot;txtTransmission&quot;)
rs(&quot;VINnum&quot;)=Session(&quot;txtVIN&quot;)
rs(&quot;Ext_Color&quot;)=Session(&quot;txtColor&quot;)
rs(&quot;Mileage&quot;)=Session(&quot;txtMileage&quot;)
rs(&quot;OurCost&quot;)= Session(&quot;txtOurCost&quot;)
rs.update
%> &quot;Damn the torpedoes, full speed ahead!&quot;

-Adm. James Farragut

Stuart
 
all items from forms are variant or strings you need to convert the item to the correct type before posting to db.

ie

mylongNo=Clng(request.form(&quot;someNoInput&quot;)

hth Bastien

There are many ways to skin this cat,
but it still tastes like chicken
 
Hey Bastien,

Thank you for your response.

I tried this

<%
dim strCost
strCost=clng(Session(&quot;txtOurCost&quot;))
%>

Prior to the insert script.

It gave me an error of Type mismatch: 'clng' Is this due to the value being inside the session? or something else? &quot;Damn the torpedoes, full speed ahead!&quot;

-Adm. James Farragut

Stuart
 
if a non numeric character is in the txtOurCost string then the clng will give an error, always check with an isnumeric before casting to a long or integer from a variant/string

eg:

if isnumeric(Session(&quot;txtOurCost&quot;)) then
strCost=clng(Session(&quot;txtOurCost&quot;))
else ' the else part is optional
ErrorMessage = &quot;Invalid input&quot;
end if
 
try using the CCur() function (or CDbl) in place of the CLng(). Long data types do not support values with decimals, which may explain your error.

good luck!
 
thank you guys,

It ended up being a conflict between a ENCTYPE=&quot;multipart/form-data&quot;

uploading pictures and trying to carry form results too.

Had to split them up to 2 forms.

&quot;Damn the torpedoes, full speed ahead!&quot;

-Adm. James Farragut

Stuart
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top