Recordset Empty Error

J

J P Singh

Hi All

Does anyone know why the code below gives me an error on the line
strTt = FormatNumber( RS("Expr1") , 2)

whenever RS is empty.

Am I doing something wrong?

<%
SQL = " SELECT Sum(PODetails.Amount) AS Expr1 FROM PODetails where PONumber=
" & rstDBEdit.Fields("PONumber").Value

Set RS = Server.CreateObject("ADODB.Recordset")
RS.Open SQL, CONN_STRING

if not rs.eof then
strTt = FormatNumber( RS("Expr1") , 2)
else
strTT= 0.00
strTT = FormatNumber( strTT , 2)
end if
Response.write strTT

%>
 
J

J P Singh

Hi Alex

Microsoft VBScript runtime error '800a000d'
Type mismatch: 'FormatNumber'

/request1.asp, line 727
 
T

TomB

Because if it's empty, it can't format it to a number.

Dim theVal
theVal=RS.Fields("Expr1").Value 'may want to change Expr1 to something a
little more helpful
if isNumeric(theVal) then
strTt=FormatNumber(theVal,2)
else
strTt="0.00" 'or whatever else the default should be.
end if


There's an FAQ at www.aspfaq.com about the isNumeric function - which you
may wish to review.
 
J

J P Singh

Top Man

Works like a charm


TomB said:
Because if it's empty, it can't format it to a number.

Dim theVal
theVal=RS.Fields("Expr1").Value 'may want to change Expr1 to something a
little more helpful
if isNumeric(theVal) then
strTt=FormatNumber(theVal,2)
else
strTt="0.00" 'or whatever else the default should be.
end if


There's an FAQ at www.aspfaq.com about the isNumeric function - which you
may wish to review.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top