#1
  1. No Profile Picture
    Contributing User
    ASP Adventurer (500 - 999 posts)

    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
  3. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    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
  4. #3
  5. No Profile Picture
    Contributing User
    ASP Explorer (0 - 99 posts)

    Join Date
    Oct 2012
    Posts
    49
    Rep Power
    3
    if objrs("field1") & "" = "" then response.write "is null or blank"
  6. #4
  7. Contributing User
    ASP Skiller (1500 - 1999 posts)

    Join Date
    Mar 2005
    Location
    Columbus, OH
    Posts
    1,594
    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
  8. #5
  9. No Profile Picture
    Contributing User
    ASP Adventurer (500 - 999 posts)

    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
  10. #6
  11. Contributing User
    ASP Skiller (1500 - 1999 posts)

    Join Date
    Mar 2005
    Location
    Columbus, OH
    Posts
    1,594
    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.
  12. #7
  13. No Profile Picture
    Contributing User
    ASP Adventurer (500 - 999 posts)

    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.
  14. #8
  15. No Profile Picture
    Contributing User
    ASP Explorer (0 - 99 posts)

    Join Date
    Oct 2012
    Posts
    49
    Rep Power
    3
    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
  16. #9
  17. No Profile Picture
    Contributing User
    ASP Adventurer (500 - 999 posts)

    Join Date
    Feb 2008
    Posts
    790
    Rep Power
    30
    Thanks for your input, I appreciate it.

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

IMN logo majestic logo threadwatch logo seochat tools logo