INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

IsNull assistance needed

IsNull assistance needed

(OP)
I have some code which displays various HTML elements if certain conditions are met.

At the moment, if my SQL statements are met, the page will display SHOW PRICES.

If my SQL statements are not met, the page will display NO PRICES.

This all works fine, however I'm having a problem.

If my SQL statements are met, but the record found is NULL, it will give an error.

I want to display NO PRICES if bFound = False OR (myvar) is null.

Can somebody help me with this...

CODE

<%

pickup = request.form("frmpick")
dropoff = request.form("frmdrop")

set myconn = Server.CreateObject("ADODB.connection")
connection = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &_
Server.MapPath("db.mdb") & ";"
myconn.open (connection)

set rs=Server.CreateObject("ADODB.recordset")

Dim bFound
bFound = True 

MY SQL STATEMENTS

Else
bFound = False
%>

<p>NO PRICES</p>

<%

End If

If bFound Then 
If Not RS.EOF Then
%>
						
<p>SHOW PRICES</p>						
						
<%
rs.Close
Set rs = Nothing
myconn.Close
Set myconn = Nothing
End If
End If
%> 

RE: IsNull assistance needed

Quote:

If my SQL statements are met, but the record found is NULL, it will give an error.

The error being, what exactly ??

And why does your code set bFound to true before you even run the SQL commands?

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

RE: IsNull assistance needed

(OP)
Sorry for not being clearer...

I run certain SQL statements based upon the value of a variable.

For example:

If 'pickup' is Heathrow Airport, run this query, ElseIf 'dropoff' is Heathrow Airport, run this query...

Here is my code in full:

CODE

<%

pickup = request.form("frmpick")
dropoff = request.form("frmdrop")

set myconn = Server.CreateObject("ADODB.connection")
connection = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &_
Server.MapPath("db.mdb") & ";"
myconn.open (connection)

set rs=Server.CreateObject("ADODB.recordset")

Dim bFound
bFound = True 

If pickup = "Heathrow Airport" Then

rs.Open "SELECT tbllhr.postcode, tbllhr.salbrnz, tbllhr.salsilv, tbllhr.salgold, tbllhr.estbrnz, tbllhr.mpvbrnz, tbllhr.mpvsilv, tbllhr.vanbrnz, tbllhr.vansilv FROM tbllhr WHERE tbllhr.postcode = '" & dropoff & "' ", myconn

ElseIf dropoff = "Heathrow Airport" Then

rs.Open "SELECT tbllhr.postcode, tbllhr.salbrnz, tbllhr.salsilv, tbllhr.salgold, tbllhr.estbrnz, tbllhr.mpvbrnz, tbllhr.mpvsilv, tbllhr.vanbrnz, tbllhr.vansilv FROM tbllhr WHERE tbllhr.postcode = '" & pickup & "' ", myconn

Else
bFound = False

%>

<p>NO PRICES</p>

<%

End If

If bFound Then 
If Not RS.EOF Then
%>
						
<p>SHOW PRICES</p>						
						
<%
rs.Close
Set rs = Nothing
myconn.Close
Set myconn = Nothing
End If
End If
%> 

If pickup or dropoff = Heathrow Airport then bFound = True.
When bFound = True the page SHOWS PRICES

The problem I'm having now is that if the pickup or dropoff = Heathrow Airport, BUT the record IsNull, it should show NO PRICES.

What it's doing now is:

Is pickup or drop off Heathrow Airport... YES
Then bFound is TRUE
SHOW PRICES

Is pickup or drop off Heathrow Airport... NO
Then bFound is FALSE
<html>NO PRICES


What I want to add is...

Is pickup or drop off Heathrow Airport... YES
Then bFound is TRUE
If (rs("dbfield1") Is NOT NULL And bFound is TRUE Then
<html>SHOW PRICES
Else
bFound is FALSE
<html>NO PRICES
End If


does that make more sense?

RE: IsNull assistance needed

I'm obviously missing what your problem is.


Basically All you need is;

CODE --> vBscript

If IsNull(variable) then
		'output prices
	else
		'do nothing or say sorry!
end if 

And if the value is an empty string rather than NULL

CODE --> vBscript

If variable <> "" then
		'output prices
	else
		'do nothing or say sorry!
end if 

OR if the value might be either;

CODE --> vBscript

If IsNull(variable) or variable <> "" then
		'output prices
	else
		'do nothing or say sorry!
end if 

OR if the variable is created but not initialised;


CODE --> vBscript

If IsEmpty(variable) then
		'output prices
	else
		'do nothing or say sorry!
end if 

OR

all three;

CODE --> vBscript

If IsNull(variable) or variable <> "" or IsEmpty(variable)then
		'output prices
	else
		'do nothing or say sorry!
end if 



Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

RE: IsNull assistance needed

(OP)
Thanks again Chris. I was over complicating things as usual. I have simplified the logic and it works fine.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close