none
Text box Issue RRS feed

  • Question

  • I have an interesting dilemma.

    I inherited an old Access DB written by I know not who.  There is a form with a text box that used to be a text box control limited to 255 characters.  The data in this field is used in a fixed format report.  However, the reports text box can grow was set to yes.  It was never an issue, because they were limited to 255 characters and the object had enough to display that many characters and then some.  The Enter key behavior for the forms text box field was set to default. 

    Recently, there have been some developments that I need to deal with.  Someone figured out that you could defeat the Enter key behavior with control enter to start a new line.   They also now need more characters.  I changed the field to a long text field which will allow them to enter more characters, but if they put too many characters in, the Reports text box will grow and it screws up the fixed format of the report.  I cannot use the can grow property for this field, which is fine.

    I can count the characters and know how many can physically fit in the report text box.  The report object will accommodate 714 characters, and I can prompt them when they have too many.  However I don’t know how to deal with the New Lines they are inserting into the field as they do not count in the total characters count. 

    The report text box object will accommodate 714 characters in 5 lines.  Can anyone give me some pointers for how to deal with this?  I hope I have explained it well enough.

    Wednesday, May 16, 2018 7:35 PM

Answers

  • To all,

    Thanks for all your feedback and suggestions.

    I decided to take the lazy mans way out.   Due to all your feedback, I think I could write code to take care of it.  However, the user did not want to pay me for this feature.  As a result, they were satisfied with me placing a warning message on the data entry form stating the number of characters permitted and the number of lines permitted.  I am now checking the total number characters and giving them a message if they exceed it.  I am not counting the number of lines.  They say they will stay within the constraints.  I do not like this, but that is what they have decided since they do not want to pay for additional error checking that I believe I could provide.  We will see if they are willing to pay for additional development when they have a problem.  Thanks for all your help in this matter.

    • Marked as answer by tkosel Saturday, May 26, 2018 11:43 PM
    Saturday, May 26, 2018 11:43 PM

All replies

  • Hi,

    In the query source for your Report, you could add a calculated column using the Left$() function to trim the text in the table to only display the first 714 characters.

    Just a thought...

    Wednesday, May 16, 2018 7:40 PM
  • Also, I think a carriage return is actually two (2) characters: enter and line feed.
    Wednesday, May 16, 2018 7:41 PM
  • Thanks for your responses, but neither helps me.  I need a way of notifying the user that s/he has either exceeded 714 total characters or more than 5 lines.  I realize that the enter key produces 2 characters, carriage return line feed  but counting them as part of the total does not benefit me since they may or may not affect the total number of lines, since text wrapping will also create new lines.
    Wednesday, May 16, 2018 8:18 PM
  • Hi,

    If you want to notify the user, you can either do so when they're done editing or use the Change event of the Textbox and its Text property to notify them as soon as they exceed the limit and possibly stop accepting any further entries at that point.

    As for counting lines, you can try to determine the number of characters that fit in one line and then use the Mod function to count the lines based on the number of characters - adjusting for carriage returns, of course.

    Hope it helps...

    Wednesday, May 16, 2018 8:24 PM
  • The report text box object will accommodate 714 characters in 5 lines.  Can anyone give me some pointers for how to deal with this?  I hope I have explained it well enough.

    Hi tkosel,

    It is better to do some kind of analysis in the BeforeUpdate event of the control, instead of doing this analysis during the generation of the report.

    This analysis could be that you do a Split of the text_value with separator vbCrLf. Using UBound you can easily see how many lines are used, and per line you can see how many characters you have.

    Imb.

    Wednesday, May 16, 2018 8:45 PM
  • Hello tkosel,

    >>However I don’t know how to deal with the New Lines they are inserting into the field as they do not count in the total characters count. 

    Once you use Enter to add a new line in the text box, a line break was inserted in the end of the previous line. So we could try to remove the line break and then count the text string.

    Such as 

    Len(Replace(Replace(Me.Text0.text, vbNewLine, ""), vbCrLf, ""))

    Best Regards,

    Terry

     


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, May 17, 2018 7:06 AM
  • Terry and all,

    Thanks for your responses.  Terry, I cannot get your code to do what I need, I am not familiar with the Replace Operator.  It will not do me any good to replace the CR LF with nothing anyhow, as they want a new line in the text box.  I can count the number of chars fine, but I also need to count how many lines there are regardless of if a new line is caused by normal wrapping or CR LF.

    Thursday, May 17, 2018 3:51 PM
  • The report text box object will accommodate 714 characters in 5 lines.  Can anyone give me some pointers for how to deal with this?  I hope I have explained it well enough.

    Hi tkosel,

    It is better to do some kind of analysis in the BeforeUpdate event of the control, instead of doing this analysis during the generation of the report.

    This analysis could be that you do a Split of the text_value with separator vbCrLf. Using UBound you can easily see how many lines are used, and per line you can see how many characters you have.

    Imb.

     imb, Thanks for your response, your point is well taken.  I had planned to do the evaluation in either the beforeupdate or afterupdate event of the control.  I am not familiar with how to use the UBound function to perform this analysis, could you provide a little more information?


    • Edited by tkosel Thursday, May 17, 2018 4:11 PM
    Thursday, May 17, 2018 4:10 PM
  • Hi,

    Do you know how many characters per line when word-wrapping? If so, maybe you could take the total number of characters and divide it by the number of characters per line. For example, let's say there are 100 chars per line when word-wrapping and you counted a total of 933 characters. Then 933\100 = 9 lines and 933 Mod 100 = 33 characters left.

    Now, to count the number of carriage returns, you can use the code Terry provided. However, to determine the actual number of lines when word-wrapping will probably involve writing a custom function combining the above idea of dividing the number of characters with a fix number but also take into account the placements of each carriage return.

    Just my 2 cents...

    Thursday, May 17, 2018 4:16 PM
  • I had planned to do the evaluation in either the beforeupdate or afterupdate event of the control.  I am not familiar with how to use the UBound function to perform this analysis, could you provide a little more information?

    Hi tkosel,

    You can study the next code in the debug mode, to understand what happens:

    Sub Regels() Dim regel As String Dim regel_arr() As String Dim nr_lines As Integer Dim nr_chars As Integer dim x as Integer

    regel = "regel 1" & vbCrLf & vbCrLf & "regel 3 met extra" regel_arr = Split(regel, vbCrLf) nr_lines = UBound(regel_arr) + 1

    For x = 0 to UBound(regel_arr) nr_chars = Len(regel_arr(x))
    Next End Sub


    You can calculate the number of lines, based on the vbCrLf's in the input string using UBound of the array.

    Then you can loop through the array to calculate the number of characters per member. If this number exceeds a certain limit you must account for an additional line because of wrapping.

    You can put the (modified to your needs) code in a function, that returns a (boolean) True when the text is too long. The True-value generates a message "Too long or too many lines", and sets the Cancel parameter in the BeforeUpdate event to True,

    Imb.


    • Edited by Imb-hb Thursday, May 17, 2018 9:47 PM or too many lines
    Thursday, May 17, 2018 9:38 PM
  • To all,

    Thanks for all your feedback and suggestions.

    I decided to take the lazy mans way out.   Due to all your feedback, I think I could write code to take care of it.  However, the user did not want to pay me for this feature.  As a result, they were satisfied with me placing a warning message on the data entry form stating the number of characters permitted and the number of lines permitted.  I am now checking the total number characters and giving them a message if they exceed it.  I am not counting the number of lines.  They say they will stay within the constraints.  I do not like this, but that is what they have decided since they do not want to pay for additional error checking that I believe I could provide.  We will see if they are willing to pay for additional development when they have a problem.  Thanks for all your help in this matter.

    • Marked as answer by tkosel Saturday, May 26, 2018 11:43 PM
    Saturday, May 26, 2018 11:43 PM
  • Hey,

    The customer is always right. Right?

    Good luck!

    Sunday, May 27, 2018 1:44 AM
  • The customer is always right. Right?

    Yes, within the possibilities and constraints I have, the customer is always right.

    Imb.

    Sunday, May 27, 2018 1:16 PM