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!

hide session variable if recordset is 2

Status
Not open for further replies.

aonefun

Technical User
May 21, 2007
79
US
I am creating a Session variable in my code as follows:

Session("VendorPartNumber") = (Recordset1.Fields.Item("ManufacturerPartNumber").Value)

I receive this error message: "Requested operation requires a current record" when ManufacturerPartNumber is empty.

Is there an IF statement that I can place the session code into to avoid the error message or is there an alternative method?

 
Code:
if Recordset1.EOF AND Recordset1.BOF then
'recordset is empty...
else
Session("VendorPartNumber") = (Recordset1.Fields.Item("ManufacturerPartNumber").Value)
end if

-DNG
 
just wanted to clarify that if you do not want to use an else...you don't need to...it's often used for a message like dng has in a comment or good for debugging

Code:
' open database connection
' execute sql

if NOT Recordset1.EOF then
Session("VendorPartNumber") = (Recordset1("ManufacturerPartNumber"))
end if

 
Thank you so much for the information.

However, I have now changed the code so that the session variable equals a Request.Form, as follows:

Session("VendorPartNumber") = Request.Form("VendorPartNumber")

How would I put the following into correct syntax:

If Request.Form("VendorPartNumber") IS NOT NULL (or do I use empty)
THEN
Session("VendorPartNumber") = Request.Form("VendorPartNumber")

Can I then create something like

Else
Session("VendorParNumber") = "EMPTY VALUE"

because I'm afraid the next page requires a value for the session variable.

Thanks for your valuable time!
 
NULL and an empty string are two separate values. Often, if I need to look for both of them, what I do is what you indicated in your post.
Code:
if myVal = "" or isNull(myVal) then

------------------------------------------------------------------------------------------------------------------------
"Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing ever happened."
- Winston Churchill
 
Or, you can append a blank string to the value in the comparison, which turns a Null value into a blank string. For example;

if (myVal & "") = "" Then
'myVal is either null, or a blank/empty string
else
'myVal has something in it.
end if

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top