dcsimg
Results 1 to 9 of 9

Thread: [RESOLVED] Adding Extra space after text in a textbox when it is retrieved from another form

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2014
    Posts
    273

    Resolved [RESOLVED] Adding Extra space after text in a textbox when it is retrieved from another form

    When I am retrieving data from frmItemDetails to frmSalesInvoice textboxes, it adds one more extra space after text in each textbox in frmSalesInvoice textboxes. How can I avoid this?

    Code:
     frmNewSalesInvoice.txt14.Text = Me.txtDescription.Text
            frmNewSalesInvoice.txt15.Text = Me.txtModelNumber.Text
    Example : ModelNumber "Dolly 033" becomes "Dolly 033 "

    Thanks.

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    32,755

    Re: Adding Extra space after text in a textbox when it is retrieved from another form

    That's not happening. When you access a property, you get what's there, not what's there...plus a few bonus characters. If you really ARE getting those spaces, then they are present in the source, as well. Anything else would have broken more programs than you've even heard of, so you can be pretty confident that something else is going on.

    However, you can always remove extra spaces at front and back of a string with String.Trim.
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2014
    Posts
    273

    Re: Adding Extra space after text in a textbox when it is retrieved from another form

    The following code is also not working :
    Code:
    frmNewSalesInvoice.txt14.Text = Trim(Me.txtDescription.Text)
    Actually, it shows text without extra space in textbox while retrieving. But once it is saved, it shows with extra space both in the textbox as well as in the database table.

  4. #4
    Hyperactive Member
    Join Date
    Nov 2017
    Posts
    465

    Re: Adding Extra space after text in a textbox when it is retrieved from another form

    I was just going to make a post assuming that the data is tied to a database table. How is the field defined in the database (field type, length, etc.)? Some field types pad the data with spaces so that each character is used (char does, as opposed to varchar which doesn't for example). That's almost certainly what is happening here.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2014
    Posts
    273

    Re: Adding Extra space after text in a textbox when it is retrieved from another form

    The following are the field details of MS Access Table where the text is saved:
    Attached Images Attached Images  
    Last edited by VS2013; Dec 29th, 2017 at 06:23 PM.

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    40,350

    Re: Adding Extra space after text in a textbox when it is retrieved from another form

    Unless the text is always becoming exactly 255 characters (so 5 proper characters would have 250 spaces after it), the field is not the issue.

    How are you loading and saving the data?

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2014
    Posts
    273

    Re: Adding Extra space after text in a textbox when it is retrieved from another form

    There are few textboxes which I am entering data manually are saved correctly (without any extra space at the end of the text). And some of the textboxes which are automatically filled data from another form is having extra space in the end of the text.
    Code:
    Dim StrSql = "INSERT INTO NewSalesDBTable (A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15,A16,A17,A18,A19,A20,A21,A22,A23,A24,A25,A26,A27,A28,A29,A30,A31,A32,A33,A34,A35,A36,A37,UDO,UDB) VALUES('" _
                             + Me.txt1.Text + " ','" _
                             + Me.txt2.Text + " ','" _
                             + Me.txt3.Text + " ','" _
                             + Me.txt4.Text + " ','" _
                             + Me.txt5.Text + " ','" _
                             + Me.txt6.Text + " ','" _
                             + Me.txt7.Text + " ','" _
                             + Me.txt8.Text + " ','" _
                             + Me.txt9.Text + " ','" _
                             + Me.txt10.Text + " ','" _
                             + Me.txt11.Text + " ','" _
                             + Me.txt12.Text + " ','" _
                             + Me.txt13.Text + " ','" _
                             + Me.txt14.Text + " ','" _
                             + Me.txt15.Text + " ','" _
                             + Me.txt16.Text + " ','" _
                             + Me.txt17.Text + " ','" _
                             + Me.txt18.Text + " ','" _
                             + Me.txt19.Text + " ','" _
                             + Me.txt20.Text + " ','" _
                             + Me.txt21.Text + " ','" _
                             + Me.txt22.Text + " ','" _
                             + Me.txt23.Text + " ','" _
                             + Me.txt24.Text + " ','" _
                             + Me.txt25.Text + " ','" _
                             + Me.txt26.Text + " ','" _
                             + Me.txt27.Text + " ','" _
                             + Me.txt28.Text + " ','" _
                             + Me.txt29.Text + " ','" _
                             + Me.txt30.Text + " ','" _
                             + Me.txt31.Text + " ','" _
                             + Me.txt32.Text + " ','" _
                             + Me.txt33.Text + " ','" _
                             + Me.txt34.Text + " ','" _
                             + Me.txt35.Text + " ','" _
                             + Me.txt36.Text + " ','" _
                             + Me.txt37.Text + " ','" _
                             + Me.txtUDO.Text + " ','" _
                             + Me.txtUDB.Text + " ')"
    Last edited by VS2013; Dec 30th, 2017 at 06:47 AM.

  8. #8
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    40,350

    Re: Adding Extra space after text in a textbox when it is retrieved from another form

    Based on that code, ALL of the fields should have a space added to the end of the data, because you are explicitly adding them (using "<space>','" rather than "','").

    This is another reason you should be using Parameters when working with databases. For an explanation of other reasons (and links to code examples), see the article Why should I use Parameters instead of putting values into my SQL string? from our Database Development FAQs/Tutorials (at the top of the Database Development forum).

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2014
    Posts
    273

    Re: Adding Extra space after text in a textbox when it is retrieved from another form

    Thanks for your kind support.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width