I have co-workers cutting and pasting names into the database name field and some of them are having an empty space in front of the name. Is there a way to get rid of the space or add a valadation for this? What is wrong with these people, this is just laziness at its best!
When a search for names is brought up, they are not shown due to the space

so they are not in A - Z order...
Here is a function that removes spaces. Use it an update query. Just two qustions, why are you copying and pasting? And why not import from Excel by automation?
Function OneSpace(pstr As String) As String
'*******************************************
'Purpose: Removes excess spaces from a string
'Input: ? onespace(" now is the time for all good men ")
'Output: "now is the time for all good men"
'*******************************************
Dim strHold As String
strHold = Trim(pstr)
Do While InStr(strHold, " ") > 0
strHold = Left(strHold, InStr(strHold, " ") - 1) & Mid(strHold, InStr(strHold, " ") + 1)
Loop
OneSpace = strHold
End Function
Was this answer helpful ?
Yes No
Quote:
| Originally Posted by TanisAgain Here is a function that removes spaces. Use it an update query. Just two qustions, why are you copying and pasting? And why not import from Excel by automation?
Function OneSpace(pstr As String) As String
'*******************************************
'Purpose: Removes excess spaces from a string
'Input: ? onespace(" now is the time for all good men ")
'Output: "now is the time for all good men"
'*******************************************
Dim strHold As String
strHold = Trim(pstr)
Do While InStr(strHold, " ") > 0
strHold = Left(strHold, InStr(strHold, " ") - 1) & Mid(strHold, InStr(strHold, " ") + 1)
Loop
OneSpace = strHold
End Function |
They copying from a dos screen
THANKS!
Ok so to use this function after putting in a module I am to
OneSpace(fieldname) in the query?
Was this answer helpful ?
Yes No
Yeah, use it in an update query.
UPDATE tblYourTableName SET tblYourTableName.YourTextField = onespace([YourTextField]);
Was this answer helpful ?
Yes No