Results 1 to 7 of 7
  1. #1
    VSCurtis is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Dec 2014
    Posts
    65

    Field Cannot Be A Zero Length String Error

    Hi Guys,

    Have a strange error going on that makes no sense. I'm getting the error tblCards.Description cannot be a zero length string while trying to save a record. The field in question is a long text field and is not required and does not allow zero length strings. At the time of entering the record I am only entering data in the Card Name Field. All other fields are left blank. I have entered records before and left this field blank without issue. Now Access is raising an error. Don't understand what's going on. Any help you can provide is appreciated. Here's the procedure being executed at the time of the error.

    Code:
    Private Sub SaveCardData(ByVal sNewKey As String)
    Dim vCardType As Variant
    If Not IsNull(sNewKey) Then
       rsCards("Card ID") = sNewKey
    End If
    If Not IsNull(txtCardName.Text) Then
       rsCards("Card Name") = txtCardName.Text
    End If
    If cmbCardCategory.ListIndex > -1 Then
       rsCards("Category ID") = cmbCardCategory.Value
    End If
    If cmbCardAttribute.ListIndex > -1 Then
       rsCards("Attribute ID") = cmbCardAttribute.Value
    End If
    If cmbCardCategory.Value = "M" Then
       txtLevel.SetFocus
       If Not IsNull(txtLevel.Text) Then
          rsCards("Level") = txtLevel.Text
       End If
       If cmbMonsterType.ListIndex > -1 Then
          rsCards("Monster ID") = cmbMonsterType.Value
       End If
       txtAttackPoints.SetFocus
       If Not IsNull(txtAttackPoints.Text) Then
         rsCards("Attack Points") = txtAttackPoints.Text
       End If
       txtDefensePoints.SetFocus
       If Not IsNull(txtDefensePoints.Text) Then
          rsCards("Defense Points") = txtDefensePoints.Text
       End If
       If lstCardType.ItemsSelected.Count > 0 Then
          For Each vCardType In lstCardType.ItemsSelected
             If lstCardType.ItemData(vCardType) = "PDM" Then
                txtPendulumScale.SetFocus
                If Not IsNull(txtPendulumScale.Text) Then
                   rsCards("Pendulum Scale") = txtPendulumScale.Text
                 End If
                 txtLink.SetFocus
                 If Not IsNull(txtLink.Text) Then
                    rsCards("Link") = txtLink.Text
                 End If
                 Exit For
             End If
          Next vCardType
       End If
    End If
    txtDescription.SetFocus
    If Not IsNull(txtDescription.Text) Then
       rsCards("Description") = txtDescription.Text
    End If
    rsCards("Forbidden") = chkForbidden.Value
    rsCards.Update
    rsCards.Bookmark = rsCards.LastModified
    SaveCardTypeData (sNewKey)
    End Sub


  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    See if this helps:

    http://www.baldyweb.com/ValueText.htm

    in particular #2.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    VSCurtis is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Dec 2014
    Posts
    65
    I read the page at the link you provided. Per that page Following this thinking, the only time the .Text property is required is when one needs to deal with what a control currently contains, rather than the saved data, such as examining what the user is typing, keystroke by keystroke. I AM concerned with what the control currently contains, as I am trying to save the record. So I'm not sure how this helps.

  4. #4
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You are testing the .Text property for Null, which it can never contain. You want the .Value property, which also means you don't have to set focus first.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    VSCurtis is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Dec 2014
    Posts
    65
    I think I understand now. You're right. Null only applies to the database field itself. My bad. I'll make some changes to the code. That setfocus stuff was diving me crazy anyway. Thanks for drawing attention to my stupid mistake. I'm a little rusty.

  6. #6
    VSCurtis is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Dec 2014
    Posts
    65
    Problem fixed. Thanks for the assist. Probably should go through the rest of my code and do the same thing.

  7. #7
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 7
    Last Post: 09-23-2016, 01:04 PM
  2. Replies: 6
    Last Post: 12-07-2015, 02:09 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