Home > Microsoft Access Help > Blanks in front of data?

Blanks in front of data?



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...

    
Guest


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   
Guest


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   
Guest


Yeah, use it in an update query.



UPDATE tblYourTableName SET tblYourTableName.YourTextField = onespace([YourTextField]);

Was this answer helpful ? Yes No   
Guest
 
 
Home - About Infoqu - Contact - Privacy Statement - Link to Infoqu - Bookmark Infoqu

Copyright 2007-2008 by Infoqu. All rights reserved