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

IsNull assistance needed

Status
Not open for further replies.

axLW

Programmer
Feb 6, 2015
110
GB
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
%>

[b]<p>NO PRICES</p>[/b]

<%

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 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
 
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?
 
I'm obviously missing what your problem is.


Basically All you need is;

Code:
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:
If variable <> "" then
		'output prices
	else
		'do nothing or say sorry!
end if

OR if the value might be either;

Code:
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:
If IsEmpty(variable) then
		'output prices
	else
		'do nothing or say sorry!
end if

OR

all three;

Code:
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
 
Thanks again Chris. I was over complicating things as usual. I have simplified the logic and it works fine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top