Connecting Tech Pros Worldwide Forums | Help | Site Map

Trimming Irrelevant Data

Newbie
 
Join Date: Aug 2007
Posts: 2
#1: Aug 23 '07
Hi all,

I need some help. I have a table contaning a fair few fields, one of which is [EmployeeName]. This field has bits of irrelavant data joined together with the employee names which i'd like to get rid off through either a query or vba. I know exactly what the irrelevant data items are i.e. "Manager" and "1"

For example: "John Smith Manager" needs to become "John Smith"
For example: " John Smith1" needs to also become "John Smith"
For example: "Mary Smith 1" needs to also become "Mary Smith"

Any help would be greatly appreciated, as at the minute, I'm using the find and replace function in the table view, which I'm having to do daily :-(

Thank you so much,

Jase

Expert
 
Join Date: Aug 2007
Posts: 122
#2: Aug 23 '07

re: Trimming Irrelevant Data


Maybe you need to look at why you are having to do this daily, instead of how code can fix this. Any code I could give you would only be emulating the find and replace function, and so would still have to be run daily (maybe it could be done automatically, but that's not the point).

You need to look at the input to the database, and figure out why this keeps happening.
Newbie
 
Join Date: Aug 2007
Posts: 2
#3: Aug 23 '07

re: Trimming Irrelevant Data


Quote:

Originally Posted by Stwange

Maybe you need to look at why you are having to do this daily, instead of how code can fix this. Any code I could give you would only be emulating the find and replace function, and so would still have to be run daily (maybe it could be done automatically, but that's not the point).

You need to look at the input to the database, and figure out why this keeps happening.

Unfortunately, the population of the data output is beyond my control, and if i could get hold of some code, atleast it could be scheduled to run daily, rather than a manual fix each day. Any help would be appreicated
Expert
 
Join Date: Aug 2007
Posts: 122
#4: Aug 23 '07

re: Trimming Irrelevant Data


Try this, and let me know if you have any problems:
Expand|Select|Wrap|Line Numbers
  1. Dim rs as DAO.recordSet
  2. Set rs = DBEngine(0)(0).openRecordSet("SELECT EmployeeName FROM yourTable;")
  3. Do While NOT rs.EOF
  4.     dim changed as boolean 'efficiency
  5.     changed = false
  6.     dim new as String
  7.     new = rs!EmployeeName
  8.     dim pos as Integer
  9.     pos = InStr(new, "1")
  10.     Do While pos <> 0
  11.          changed = true
  12.          new = left$(new, pos - 1) & mid$(new, pos + 1)
  13.          pos = InStr(new, "1")
  14.     Loop
  15.     pos = InStr(new, "Manager")
  16.     Do While pos <> 0
  17.          changed = true
  18.          new = left$(new, pos - 1) & mid$(new, pos + 8)
  19.          pos = InStr(new, "Manager")
  20.     Loop
  21.     If changed Then
  22.          DoCmd.runSQL("UPDATE yourTable SET EmployeeName = '" & new & "' WHERE EmployeeName = '" & rs!EmployeeName & "';")
  23.     End If
  24.     rs.MoveNext
  25. Loop
  26.  
Reply