Notices

Great community. Great ideas.

Welcome to ASP/Free, a community dedicated to helping beginners and professionals alike in improving their knowledge of Microsoft's development and administration technologies. Sign up today to gain access to the combined insight of tens of thousands of members.

Thread: isnull and blank with if/then statement

Results 1 to 9 of 9
Share This Thread →
  1. #1
    phoenixaz is offline Contributing User
    Join Date
    Feb 2008
    Posts
    790
    Rep Power
    30

    isnull and blank with if/then statement

    I have 10 fields that I want to check if they are both null or blank. Is there an easy way to do that?

    I have been using something like this..

    if isnull (objrs ("field1")) and isnull (objrs ("field 2")) and isnull (objrs ("field3")) ......isnull (objrs ("field10")) then
    'something

    This doesn't check for objrs ("field1") = "" and objrs ("field2") = "" etc.....

    So is there a way to combine isnull and blank and not have to list all of them like above.

    Thanks for your help.

  2. #2
    KLynch0803 is offline Registered User
    Join Date
    Jan 2010
    Posts
    24
    Rep Power
    0

    Talking

    I use this on my forms

    Code:
    ' Form validation vars
    dim errorsontheform(10)
    dim formerrors(12)
    formerrors(0) = "Need Frist Name"
    formerrors(1) = "Need Last Name"
    formerrors(2) = "Need Address"
    formerrors(3) = "Need City"
    formerrors(4) = "Need State"
    formerrors(5) = "Need Zipcode"
    formerrors(6) = "Need Phone"
    formerrors(7) = "Need Email"
    formerrors(8) = "Need Fence Style"
    formerrors(9) = "Need Lead Time"
    formerrors(10) = "Need Comments"
    ' This flags an error in data entry
    formerrors(11) = 0
    
    
    
    if request.form("submit") <> "" then
    	for i = 0 to 10
    		getthisform = thisformname & i
    		formvalues(i) = request.form(getthisform)
    	next
    	ValidateForm
    	if formerrors(11) = 0 then
    	response.redirect("http://YOURSITE/Confirm.asp")	
    	end if
    	Session("FirstPass") = "no"
    	Session("ThisForm") = formvalues
    end if

  3. #3
    sqlconfused is offline Contributing User
    Join Date
    Oct 2012
    Posts
    49
    Rep Power
    2
    if objrs("field1") & "" = "" then response.write "is null or blank"

  4. #4
    gk53's Avatar
    gk53 is offline Contributing User
    Join Date
    Mar 2005
    Location
    Columbus, OH
    Posts
    1,538
    Rep Power
    278
    the simple solution is

    Code:
    if trim(objrs ("field1") & " ")="" then
    response.write "empty field"
    end if
    GK
    __________________________________________________ _____
    if you found this post is useful click Give Rep button (bottom side on this reply ) and agree

  5. #5
    phoenixaz is offline Contributing User
    Join Date
    Feb 2008
    Posts
    790
    Rep Power
    30
    Code:
    So are you saying that this code covers both null and blank?
    if trim(objrs ("field1") & " ")="" then
    If the answer is yes, then back to the original question about not having to repeat the code below. Is there an easier way rather than having to list each one? Can you do a between Field1 - Field2:

    Code:
    if isnull (objrs ("FIELD1")) or objrs("FIELD1") = ""  and isnull (objrs ("FIELD2")) or objrs("FIELD2") = ""   and isnull (objrs ("FIELD3")) or objrs("FIELD3") = ""   and isnull (objrs ("FIELD4")) or objrs("FIELD4") = ""   and isnull (objrs ("FIELD5")) or objrs("FIELD5") = ""   and isnull (objrs ("FIELD6"))  or objrs("FIELD6") = ""  and isnull (objrs ("FIELD7")) or objrs("FIELD7") = ""  and isnull (objrs ("FIELD8")) or objrs("FIELD8") = ""  and isnull (objrs ("FIELD9")) or objrs("FIELD9") = ""  and isnull (objrs ("FIELD10"))  or objrs("FIELD10") = ""  then

  6. #6
    gk53's Avatar
    gk53 is offline Contributing User
    Join Date
    Mar 2005
    Location
    Columbus, OH
    Posts
    1,538
    Rep Power
    278
    Yes. It is covers both
    if you want all in one statement you can do something like

    Code:
    if trim(objrs("field1") & objrs("field2") &  objrs("field3") & objrs("field4") & objrs("field5") & objrs("field6") & objrs("field7") & objrs("field8") & objrs("field9") & objrs("field10") & " " )="" then
    response.write "All fields empty"
    end if
    or
    Code:
    for i=1 to 10
    fldname="field" & i
    if trim(objrs(fldname) & " ")="" then
    response.write "missing value in field" & i & "<br>"
    end if
    next
    Last edited by gk53; November 6th, 2012 at 03:20 PM.

  7. #7
    phoenixaz is offline Contributing User
    Join Date
    Feb 2008
    Posts
    790
    Rep Power
    30
    Thank you for that! Both of those do the job more efficiently that my code.

    I appreciate your time.

  8. #8
    sqlconfused is offline Contributing User
    Join Date
    Oct 2012
    Posts
    49
    Rep Power
    2
    The simple solution is to just add double quotes. Adding a space and then trimming it is the same result as what I spoted. Why complicate things?

    Code:
    if objrs("field1") & objrs("field2") &  objrs("field3") & objrs("field4") & objrs("field5") & objrs("field6") & objrs("field7") & objrs("field8") & objrs("field9") & objrs("field10") & "" ="" then
    response.write "All fields empty"
    end if

  9. #9
    phoenixaz is offline Contributing User
    Join Date
    Feb 2008
    Posts
    790
    Rep Power
    30
    Thanks for your input, I appreciate it.

Share This Thread →

Become Part of This Conversation

Join NowFor Free!

Similar Threads

  1. Not Isnull
    By ldoodle in forum ASP Development
    Replies: 9
    Last Post: August 6th, 2010, 08:15 AM
  2. Blank Fields Causing Blank Queries
    By Evil Creamsicle in forum Microsoft Access Help
    Replies: 3
    Last Post: April 24th, 2009, 04:43 PM
  3. If statement posting when blank
    By jesushax in forum ASP Development
    Replies: 8
    Last Post: January 31st, 2008, 06:41 AM
  4. If Not IsNull statement, Help rewriting it. Please
    By Asperation in forum ASP Development
    Replies: 5
    Last Post: August 16th, 2004, 09:36 PM
  5. Replies: 4
    Last Post: April 20th, 2004, 04:42 PM

ASP Free Advertisers and Affiliates