Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2002
    Posts
    68

    Unanswered: .asp to access question

    Question: I created a search .asp page that uses the "tfilter" function. I want to search my Microsoft Access Database, but my "tfilter" function will not work if my ITEMLOC is null. Is there a way for this function to work weather it ITEMLOC is null or not? My code is below:

    <%
    tfilter = " WHERE (USERNAME = '" & Request.Form("ITEM_USERNAME") & "') AND (ITEMLOC = '" & Request.Form("ITEM_LOC") & "') "
    'Response.Write tfilter & "<br>"
    %>

    Thanks,
    John316

  2. #2
    Join Date
    Feb 2002
    Posts
    2,232
    Modify tfilter to only include the username portion of the where clause. Then test the request.form("ITEM_LOC") - if it exists, then append to tfilter.

  3. #3
    Join Date
    Aug 2002
    Location
    Québec, Canada
    Posts
    109
    Use that:

    <%
    tfilter = " WHERE (USERNAME = '" & Request.Form("ITEM_USERNAME") & "') AND (ITEMLOC = '" & Request.Form("ITEM_LOC") & "" & "') "
    'Response.Write tfilter & "<br>"
    %>

    If it hard to read, basically, it is by adding & "" to your value that may be null, so the null value will become a empty string. BUT, if you have null value in your database, you must know that null values are different from empty string. To test for a null value you can use IsNull() function in VB and in SQL

    Jefb

  4. #4
    Join Date
    Sep 2002
    Posts
    68

    Jeff...

    Jeff this did not work, can you think of anything else?

    John316

  5. #5
    Join Date
    Feb 2002
    Posts
    2,232
    tfilter = " WHERE (USERNAME = '" & Request.Form("ITEM_USERNAME") & "')

    if request.form("ITEM_LOC") <> "" then

    tfilter = tfilter & " AND (ITEMLOC = '" & Request.Form("ITEM_LOC") & "') "

    end if

    Response.Write tfilter & "<br>"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •