Clear a Field in MS Access with ASP

Ask a Question related to ASP, Design and Development.

  1. #1

    Default Re: Clear a Field in MS Access with ASP

    Couple of points:

    a) Even if you set "Not Required", that just means you can enter a NULL
    value. It doesn't mean you can enter a Zero Length String. NULL <> "" (ie
    Null does not equal Zero Length String). To allow Zero Length Strings,
    there's another setting (for text fields) which says "Allow Zero Length
    Strings"

    b) When you want to update something as a NULL, you don't put single quotes
    around it - that means a literal string containing the text "NULL". What you
    want is something like:

    <%
    strSQL = _
    "UPDATE myTable " & _
    "SET myField = NULL " & _
    "WHERE UserID = 1"

    objConn.Execute strSQL,,adCmdText+adExecuteNoRecords
    %>

    Cheers
    Ken

    "James" <james.horne@roke.co.uk> wrote in message
    news:SCk0b.2$313.277@psinet-eu-nl...
    : Hopefully the title says it all. I want to delete the entry in a field in
    a
    : record in a MS Access database using ASP. Note I don't want to remove the
    : entire record - just the vlaue of one field within in. E.g. My database
    hold
    : records of people, and having entered a phone number (say), I like the
    : option to delete the value in this field.
    :
    : Within Access itself you can do "UPDATE people SET phone='Null'". However,
    : trying to run the same code via ASP in a web page fails. It also won't
    : accept "UPDATE people SET phone=''" - even though the field is set as "Not
    : Required".
    :
    : I just want to make the entry blank! How difficult can this be!
    :
    : Any ideas please,
    :
    : Thanks,
    :
    : James
    :
    :


    Ken Schaefer Guest

  2. Similar Questions and Discussions

    1. Memo Field with Access
      Hopefully someone can help me with this. I have a memo field in Access, I type for example into the text box on the webpage: (ignore the >) *...
    2. Clear an input field when user clicks in it
      Im trying to clear a value of a cfinput when the user clicks in it. i used to do this on html. <input name="" onClick="(this.value=' ')"> can...
    3. Best way to access field values using ADO.
      Is there any difference, performance-wise, between these two methods? Method 1: szSQL = "SELECT fld1, fld2, fld3 FROM tbl1" Set objRS =...
    4. MS Access Memo Field and ASP
      I have a memo field in a MS Access table. The contents of the field may look like this: 1. This is number one 2. This is number 2 3. Skipping...
    5. ASP ACCESS Db Field Size
      place the info into a memo field ================================ http://www.ASPkey.net/ A Resource Site for Web Developers *Free OnLine web...
  3. #2

    Default Re: Clear a Field in MS Access with ASP

    James wrote:
    > Hopefully the title says it all. I want to delete the entry in a
    > field in a record in a MS Access database using ASP. Note I don't
    > want to remove the entire record - just the vlaue of one field within
    > in. E.g. My database hold records of people, and having entered a
    > phone number (say), I like the option to delete the value in this
    > field.
    >
    > Within Access itself you can do "UPDATE people SET phone='Null'".
    > However, trying to run the same code via ASP in a web page fails. It
    > also won't accept "UPDATE people SET phone=''" - even though the
    > field is set as "Not Required".
    >
    Aside from missing a 'WHERE' clause, you have described the correct way to
    achieve the desired result. The problem lies elsewhere. What is the error
    message?

    --
    William Tasso - [url]http://WilliamTasso.com[/url]


    William Tasso Guest

  4. #3

    Default Re: Clear a Field in MS Access with ASP

    I found the problem thanks to Ken's message. I had the SQL setup to do this:
    "... SET field='"&value&"' WHERE ...". Consequently, although I had
    previously set the field value to be NULL, the SQL generated became ".. SET
    field='NULL' WHERE ..." - Note the extra quotes around NULL :-(

    I now have a function to check for NULL and all is fine:

    Function checkForNull(field)

    If Len(field) = 0 Then
    field = "NULL"
    Else
    field = "'"&field&"'"
    End If

    checkForNull = field

    End Function

    Thanks again,

    James


    "Ken Schaefer" <kenREMOVE@THISadOpenStatic.com> wrote in message
    news:u5Ty6liZDHA.1872@TK2MSFTNGP12.phx.gbl...
    > Couple of points:
    >
    > a) Even if you set "Not Required", that just means you can enter a NULL
    > value. It doesn't mean you can enter a Zero Length String. NULL <> "" (ie
    > Null does not equal Zero Length String). To allow Zero Length Strings,
    > there's another setting (for text fields) which says "Allow Zero Length
    > Strings"
    >
    > b) When you want to update something as a NULL, you don't put single
    quotes
    > around it - that means a literal string containing the text "NULL". What
    you
    > want is something like:
    >
    > <%
    > strSQL = _
    > "UPDATE myTable " & _
    > "SET myField = NULL " & _
    > "WHERE UserID = 1"
    >
    > objConn.Execute strSQL,,adCmdText+adExecuteNoRecords
    > %>
    >
    > Cheers
    > Ken
    >
    > "James" <james.horne@roke.co.uk> wrote in message
    > news:SCk0b.2$313.277@psinet-eu-nl...
    > : Hopefully the title says it all. I want to delete the entry in a field
    in
    > a
    > : record in a MS Access database using ASP. Note I don't want to remove
    the
    > : entire record - just the vlaue of one field within in. E.g. My database
    > hold
    > : records of people, and having entered a phone number (say), I like the
    > : option to delete the value in this field.
    > :
    > : Within Access itself you can do "UPDATE people SET phone='Null'".
    However,
    > : trying to run the same code via ASP in a web page fails. It also won't
    > : accept "UPDATE people SET phone=''" - even though the field is set as
    "Not
    > : Required".
    > :
    > : I just want to make the entry blank! How difficult can this be!
    > :
    > : Any ideas please,
    > :
    > : Thanks,
    > :
    > : James
    > :
    > :
    >
    >

    James Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139