I'm a newbie to ASP and databases. I have created a simple contact list database and an asp page that shows the contact listing. So far so good.
Here's what I have: -
<%=rs.fields("CompanyName")%> <BR>
-
<%=rs.fields("FirstName")%> <%=rs.fields("LastName")%> <BR>
-
<%=rs.fields("Title")%> <BR>
-
<%=rs.fields("Address")%> <BR>
-
<%=rs.fields("Address2")%> <BR>
-
<%=rs.fields("Address3")%> <BR>
-
<%=rs.fields("Country")%> <BR>
-
<%=rs.fields("City")%> <%=rs.fields("State")%> <%=rs.fields("Zip")%> <BR>
-
<%=rs.fields("State")%> <BR>
-
<%=rs.fields("Zip")%> <BR>
-
Tel: <%=rs.fields("WorkPhone")%> or <%=rs.fields("WorkPhone2")%> <BR>
-
Mobile: <%=rs.fields("MobilePhone")%> <BR>
-
Fax: <%=rs.fields("FaxNumber")%> Email: <a href="mailto:<%=rs.fields("EmailName")%>"><%=rs.fields("EmailName")%></a><BR>
-
The problem I have is that I want to skip the field altogether if there is no data in that field. This is the kind of result that I am trying to clean up:
Coburn Graphic Films, Incorporating.
1650 Corporate Road West
Lakewood NJ 08701
NJ
08701
Tel: 404-656-3855 or
Mobile: 404-656-3856
Fax: 404-656-7916 Email: gach@opb.state.ga.us
I guess I need and if, then, else statement to skip the blanks, but I don't know how to do it. Can anyone help?
Thanks!
-S
8 1798
You will need to check if they exist first.... - <% if LEN(rs.fields("Zip")) > 0 then
-
Response.Write(rs.fields("Zip")
-
end if%>
-
Or you could write a function to handle this. - function valueExists(input){
-
if LEN(input) > 0 then
-
Response.Write(input)
-
end if
-
}
-
-
' call the function
-
valueExists(rs.fields("Zip"))
-
Thanks for your reply. I believe your If statement will check to see if the field is greater than 0 and if so it displays the field. What I'm trying to do is a little bit more than that. If the field is greater than 0 then I would like to add some formatting code as well such as a label, the database field and then a break. So I'm looking to say this:
If the address field is greater than zero then type:
"Address: - <display field contents> <BR>"
Can you expand on your answer? Thanks!
Thanks for your reply. I believe your If statement will check to see if the field is greater than 0 and if so it displays the field. What I'm trying to do is a little bit more than that. If the field is greater than 0 then I would like to add some formatting code as well such as a label, the database field and then a break. So I'm looking to say this:
If the address field is greater than zero then type:
"Address: - <display field contents> <BR>"
Can you expand on your answer? Thanks!
- function valueExists(input, formatbegin, formatend){
-
if LEN(input) > 0 then
-
Response.Write(formatbegin & input & formatend)
-
end if
-
}
-
-
' call the function
-
valueExists(rs.fields("Zip"), "Zip Code: ","<br />")
-
Sadly I am too inexperienced to put your suggested into use. I'm flailing over here trying to get this to work. Is there any assistance you can offer? It seems a simple business, but I'm obviously missing something. I'd be happy to pay you to write this page for me.
Thanks!
-Tracy
Tracy,
Here's your example... Which will simply display everything, including fields which have no value. -
-
<%=rs.fields("CompanyName")%> <BR>
-
<%=rs.fields("FirstName")%> <%=rs.fields("LastName")%> <BR>
-
<%=rs.fields("Title")%> <BR>
-
<%=rs.fields("Address")%> <BR>
-
<%=rs.fields("Address2")%> <BR>
-
<%=rs.fields("Address3")%> <BR>
-
<%=rs.fields("Country")%> <BR>
-
<%=rs.fields("City")%> <%=rs.fields("State")%> <%=rs.fields("Zip")%> <BR>
-
<%=rs.fields("State")%> <BR>
-
<%=rs.fields("Zip")%> <BR>
-
Tel: <%=rs.fields("WorkPhone")%> or <%=rs.fields("WorkPhone2")%>
-
-
What he's suggesting that you do is have your code check to see if a field is empty before displaying it - such as the below... -
<%
-
If LEN(rs.fields("CompanyName")) > 0 Then
-
Response.Write "Company Name: " & rs.fields("CompanyName")
-
End If
-
In other words... If there is even 1 character in "CompanyName" - it will be displayed, if not, it will not be displayed. You can format it however you like.
-
<%
-
If LEN(rs.fields("CompanyName")) > 0 Then
-
Response.Write "Company Name: " & rs.fields("CompanyName")
-
End If
-
In other words... If there is even 1 character in "CompanyName" - it will be displayed, if not, it will not be displayed. You can format it however you like.
I usually do something more like: - for each x in rs.fields
-
if trim(rs(x)) <> "" then response.write x & ": " & rs(x) & "<br>" & vbNewLine
-
next
this will print out every field (if it isn't empty). If a user inputs a space in an input, the script might interpret this as important and save it to the db, in which case you do have a value: " ". My method will eliminate those as well. Of course, it is a good idea to trim every input right before you save it...
Jared
That's a really good way of doing it actually.. that will totally elimate your problem Tracy.
I'm going to adapt this method in my own work, Jared. Never thought of doing it that way before.
Mark
Genius! Even I understood that. Thank you so much!!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: MX1 |
last post by:
Hi,
I have a report with Name1 and Name2 in the address section . Sometimes,
Name2 is not populated with data via the query that feeds the report.
Unfortunately, the blank line stays in the...
|
by: Steve Jorgensen |
last post by:
I often come up with logic like this somewhere in a function:
....
If Not IsNull(<some expression>) Then
<default action>
Else
<alternative action>
End If
....
|
by: Melissa |
last post by:
Does anyone have a generic procedure for adding blank lines to reports like
Sales details, PO details and/or Orders details. The procedure would need to
count the number of line items, determine...
|
by: Marlene |
last post by:
Hi All
I have the following scenario, where I have found all the duplicates
in a table, based on an order number and a part number (item).I might
have something like this:
Order PODate Rec...
|
by: BradC |
last post by:
I have a big VS 2002/2003 annoyance, and wondering if there is a way to turn
it off:
Put your cursor at the start of an indented line of code inside a function.
(right before the first...
|
by: Olveres |
last post by:
Hi,
I have managed to work out how to add new lines into a calculated text
box. However in this text box some of the outcome fields are empty
however when previewing the report it includes the...
|
by: Justin Fancy |
last post by:
Hi everyone,
I need some help. I'm placing text files into a created database using
vb.Net. The problem is that, i need two seperate sql statements to add
both files because they are in...
|
by: ShaeMills via AccessMonster.com |
last post by:
In my table I imported from .txt, one of my columns has blank spaces.
The column is as follows, how do I eliminate the blank spaces in between the
second and third, and fifth and sixth digits?
...
|
by: MLH |
last post by:
I'm using A97 import data wizard to import text file N2 a
table. The text file is a DIR listing produced by running
dir jdc*.* /s c:\JDCs.txt
The wizard is chopping the lines off at the...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |