Results 1 to 6 of 6
  1. #1
    MadTom's Avatar
    MadTom is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jun 2018
    Location
    CT and VT
    Posts
    206

    cannot be a zero-length string

    I get this error if I enter text into a Note textbox on a form and then go and delete all the text. (Field 'tblParts.P_Notes' cannot be a zero-length string.) Err 3315
    I know the difference from Null and Blank or no text and have read many posts on this subject.
    I have this code for the text box, and if I remove this Trim code I don't get the error. code to remove blank spaces.
    I use this code in other text boxes and I don't get the error?

    Code:
    Private Sub txtNotes_AfterUpdate()
    On Error Resume Next
       Me.[txtNotes] = Trim(Me.[txtNotes])
    End Sub
    Is there a work around or should I change ZLS setting? Just what to know why and what should be done.
    Thanks for all the help!


    Tom

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,535
    Sounds like you just need to change the Allow Zero Length Setting to Yes.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    MadTom's Avatar
    MadTom is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jun 2018
    Location
    CT and VT
    Posts
    206
    That does fix the problem and let's me use the Trim code.
    I don't know why other text boxes don't give me an error?
    Thanks for your help.
    Tom

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2016
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Perhaps the other text boxes have real data -- not just a space that you TRIM away.
    OR
    Perhaps other text boxes have AllowZeroLength Yes.

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,778
    I suspect that somewhere somehow you've already put zls in the data (before or after the value) before you get to this point. To test that, I would probably set the property to allow zls, do the trims and then create a query that searches these problem fields with "" as criteria (any records returned will be those where the field contains zls). If I knew how to search for zls and data in the same field I would have suggested that instead. What I don't get is why you're doing that in the code you show, unless you don't want leading spaces, which I suppose Access will allow. However, IIRC it won't allow trailing spaces anyway, so there ought to be no need to trim those if that's the intent.
    Last edited by Micron; 03-08-2020 at 08:17 PM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    MadTom's Avatar
    MadTom is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jun 2018
    Location
    CT and VT
    Posts
    206
    I can't seem to get the error in other fields, I did a query test as Micron suggested. The only thing that is different is the Notes field is set to Long Text.
    I like using TRIM to remove leading spaces, some times spaces are added when using cut & paste.
    I thank you all for your comments!
    Tom

    I will work with the ZLS set to yes if I get an error after a delete.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Field Cannot Be A Zero Length String Error
    By VSCurtis in forum Programming
    Replies: 6
    Last Post: 05-09-2017, 10:52 PM
  2. Replies: 7
    Last Post: 09-23-2016, 01:04 PM
  3. Replies: 6
    Last Post: 01-21-2014, 06:39 PM
  4. Replies: 1
    Last Post: 09-16-2013, 04:35 PM
  5. Replies: 7
    Last Post: 08-26-2013, 06:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums