VBA Len Counter when I go to a new record

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • apank
    New Member
    • Sep 2008
    • 31

    VBA Len Counter when I go to a new record

    I have a form where I have a text box counting the # of characters. I am using the following code:
    Private Sub Goal1Comments_K eyDown(KeyCode As Integer, Shift As Integer)
    'len counter for Goal 1 comments
    Me.MaxNo1 = Len(Goal1Commen ts.Text)
    In the form I have set the text box default value to "=Len([Goal1Comments])"

    It works fine, but when I proceed to the next record, it keeps the # of characters from the first record. I want it to show the # that is on the new record.

    Any help would be great.
  • missinglinq
    Recognized Expert Specialist
    • Nov 2006
    • 3533

    #2
    Originally posted by apank
    In the form I have set the text box default value to "=Len([Goal1Comments])"

    It works fine, but when I proceed to the next record, it keeps the # of characters from the first record. I want it to show the # that is on the new record.
    If you want each record to show the number of characters in ***its own Goal1Comments** * don't set the Default Value to anything, simply use the code you've got. The Default Value is designed to do exactly what it is doing, displaying the value that's assigned to it in the textbox when a new record is created.

    Welcome to Bytes!

    Linq ;0)>

    Comment

    • apank
      New Member
      • Sep 2008
      • 31

      #3
      I should have send when I go to the next record it displays the len of the record I just updated. If the first record comments is "Red Sox" the len is 7. When I go to the next record which already says "NY Yankees" the len is 10 but the text box still shows 7 until I begin typing in the comments box. I want it to display 10 when I get to that record.

      Comment

      • missinglinq
        Recognized Expert Specialist
        • Nov 2006
        • 3533

        #4
        Remove the code assigning the Default Value.
        Code:
        Private Sub Form_Current()
        If Not IsNull(Me.Goal1Comments.Value) Then
          Me.MaxNo1 = Len(Me.Goal1Comments.Value)
        Else
          Me.MaxNo1 = 0
        End If
        End Sub
        Linq ;0)>

        Comment

        • apank
          New Member
          • Sep 2008
          • 31

          #5
          The counter is still not changing when I go to another record. It's usable, but not doing what I wanted which is to show the current len when the record is displayed in the form and when I type additional comments. If the field has existing date when you get the record, I need it to display that count. Your code makes sense, but it does not seem to get the desired affect.

          Thank you by the way for taking your time to help me.

          Comment

          • missinglinq
            Recognized Expert Specialist
            • Nov 2006
            • 3533

            #6
            I don't know what else to tell you. The code is valid, assuming the names of the controls you posted are correct. Since your last post I ran up a form per your specs and it works as expected.

            If you can zip up your file and post it here I'll be happy to look at it.

            A quirk of this site is that you have to write a post, submit it, then immediately click on "Edit" then scroll down below the edit box to find the Attachment area.

            Linq ;0)>

            Comment

            • apank
              New Member
              • Sep 2008
              • 31

              #7
              You were right. I got it to work. I really appreciate your service. This site really is great.

              Comment

              • missinglinq
                Recognized Expert Specialist
                • Nov 2006
                • 3533

                #8
                Glad you got it working and glad we could help!

                Linq ;0)>

                Comment

                Working...