Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old December 20th, 2006, 05:21 PM
Authorized User
 
Join Date: Nov 2006
Location: , , .
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default formatting data

Hi,

I have table with fields 'phone' and 'fax'.
The data in these fields is in different formats like xxx-xxx-xxxx or xxx.xxx.xxxx or xxxxxxxxxx. I need to change the format of all data to one format.
How can I do that ? Can it be done thru SQL ?

Thanks
  #2 (permalink)  
Old December 21st, 2006, 06:52 AM
Friend of Wrox
 
Join Date: Sep 2003
Location: Salisbury, Wiltshire, United Kingdom.
Posts: 155
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to leehambly
Default

It can be done in SQL, but I think your easiest approach, assuming this is a one off task, is to write a function which you can modify for each format type you have... something like:

================================================== ================================
Public Function pfunAmendPhoneFormat(strInput As String, strRemove As String) As String
Dim strTemp As String
Dim intLocator As Integer

intLocator = InStr(strInput, strRemove)

Do While intLocator > 0
   strTemp = strTemp & Left(strInput, intLocator - 1)
   strInput = Right(strInput, Len(strInput) - intLocator)
   intLocator = InStr(strInput, strRemove)
Loop

If Len(strInput) > 0 Then strTemp = strTemp & strInput

pfunAmendPhoneFormat = strTemp

End Function
================================================== ================================

strInput is your input string, ie: the Telephone number you want to change "xxx-xxx-xxxx"
strRemove is the specific key you want to remove, ie: "-"

It could probably do with tidying up a bit too, but it seems to do the job. You need to run it through a query to do the update to your table... and you will need to change the strRemove for each type of character you want to remove, but it should put you in the right direction...

Good luck.
  #3 (permalink)  
Old December 22nd, 2006, 12:27 PM
Authorized User
 
Join Date: Nov 2006
Location: , , .
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for helping.



Similar Threads
Thread Thread Starter Forum Replies Last Post
formatting data skrj02 Access 1 December 23rd, 2006 03:35 PM
Formatting Data Entry in forms aRtware Access 5 May 12th, 2006 09:16 AM
General data formatting MargateFan XSLT 1 April 26th, 2006 06:53 AM
Formatting data in MsFlexGrid - How ? mike123abc Pro VB 6 2 January 8th, 2004 11:20 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.