trim spaces before and after a string

F

Ferdie Romero

I have a table which contains a lot of fields... The problem with it is that
I want to remove the leading and succeeding spaces of a string in a field. I
also want to ensure that everytime a change or an update is made, spaces
before and after the string in a field are removed...thus avoiding that
problem again...
 
A

Alex White MCDBA MCSE

Hi,

three functions that you need are :-
ltrim trim all the spaces to the left
trim trim all the spaces to the left and the right
rtrim trim all the spaces to the right

You will have to 'clean' your fields on every point of table update

e.g.

before update event

bound textbox

me.textbox1.value = trim(me.textbox1.value)

you may find it better to trap the above code on the lost focus event for
each of the relevant fields, be careful to move off the field before the
record is saved, the other event to look at is change event for the control.

because you have several fields with the problem, write a sub proc that
processes your records one by one with the following lines of code within
your loop

With TblTest
Do While Not .Eof
.fields("First_Name").value = trim("First_Name").value
.... other fields
.update
.movenext
loop
.close
end with

Hope that answers your question
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top