Results 1 to 9 of 9
  1. #1
    tylerg11 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2011
    Posts
    200

    Converting Nulls Form Entries to Zero-Length Strings


    My database is setup to not except nulls. So, on my forms, if I leave a field blank, I get an error about the Null entry. If I enter a "" in the field and tab out of it, it appears blank, but is a zero-length string entry. How can I automatically take all Null form field entries and convert them to zero-length string values before the save happens so that I don't get this error? Thanks.

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Have you looked at the Nz() function?

  3. #3
    alansidman's Avatar
    alansidman is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529
    In your table properties, set the default value to " ".

  4. #4
    tylerg11 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2011
    Posts
    200
    Quote Originally Posted by alansidman View Post
    In your table properties, set the default value to " ".
    I have. But if the field already contains data, and the user removes it, then it will error.

  5. #5
    tylerg11 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2011
    Posts
    200
    Quote Originally Posted by RuralGuy View Post
    Hane you looked at the Nz() function?
    Yes. I'm not sure completely on how I would implement it. Would it occur on data entry?

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Quote Originally Posted by tylerg11 View Post
    I have. But if the field already contains data, and the user removes it, then it will error.
    The default property *only* applies if there is no current value.

  7. #7
    alansidman's Avatar
    alansidman is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529
    In the afterupdate event for the field, try this:

    Code:
    if me.yourfieldname(isNull) then
    me.yourfieldname.value = " "
    End if

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    @Alan:
    1) You may want to make that If IsNull(Me.yourfieldname) Then
    2) You only get an AfterUpdate event *if* the user changed the control - perhaps the Exit event
    3) You can set a field to "" (ZLS) rather than " " (a single space)

  9. #9
    alansidman's Avatar
    alansidman is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529
    @Allan
    Thanks for the code correction. I was just thinking about it and came back to change it when I saw your post. I'm a little dislexic today.
    Good Point on the AfterUpdate. I like the Exit Event better.


    Alan

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

Similar Threads

  1. Converting a date to length of time
    By Duncan in forum Access
    Replies: 2
    Last Post: 11-10-2010, 05:53 AM
  2. SUM in regards to nulls
    By detlion1643 in forum Access
    Replies: 5
    Last Post: 02-03-2010, 08:50 AM
  3. Replies: 2
    Last Post: 01-18-2010, 11:52 AM
  4. GetRows - Invalid Use of Nulls
    By Wannabe_Pro in forum Programming
    Replies: 3
    Last Post: 07-22-2009, 07:07 AM
  5. Replies: 1
    Last Post: 07-14-2008, 12:15 PM

Tags for this Thread

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