un-autotrim textbox

ezfriend

Registered User.
Local time
Today, 12:13
Joined
Nov 24, 2006
Messages
242
I have two textboxes which represents a search and replace

In these text boxes, I want to allow user to type in "banana " so that it can be replace with "banananospace"

It appears that the space after "banana " is always autotrim by Access so the space at the end is trimmed off when the control lost focus. Is there a way to turn off the auto trim?

Thanks.

Ez
 
I do not believe there is a way to prevent the "Trimming". You may be able work around it though. For instance you could use the Change event and encapsulate the text in brackets thereby keeping the trailing space. To make this appear seamless to the user you could use Text1.SelStart = Len(Text1.Text) - 1 after setting the Brackets in place.

Then in the search code remove the trailing and leading brackets prior to actually searching.
It is not elegant and probably not the best solution, but it is workable.

Another solution is to tell the users to encapsulate their searches using whatever Character and omit the leading and trailing Characters prior to searching.
 
in the after update event for the text box

just put mytextbox = trim(mytextbox)

thats bound to work

---------------
sorry - if you want a single space ADDING to the string

try this in the after update event

mytextbox = trim(mytextbox) & " "

this will trim the string THEN add a space, so you get a space added always.

msgbox(len(mytextbox)) will prove it
 
Last edited:
Just a FYI. I found this script some where, but forgot what the link is so I couldn't give credit to the author.

This script appear to work for me.

Code:
Private m_sSearach As String

Private Sub txtCurrentText_AfterUpdate()
    If Nz(m_sSearch) > "" Then
        Me!txtCurrentText = m_sSearch
        m_sSearch = ""
    End If
End Sub

Private Sub txtCurrentText_BeforeUpdate(Cancel As Integer)
    If Nz(Me!txtCurrentText.Text) > "" Then
        If Left(Me!txtCurrentText.Text, 1) = Chr(32) Or Right(Me!txtCurrentText.Text, 1) = Chr(32) Then
            m_sSearch = Me!txtCurrentText.Text
        End If
    End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom