A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Query to replace unwanted characters



 
 
Thread Tools Display Modes
  #1  
Old January 22nd, 2006, 01:33 AM posted to microsoft.public.access.queries
external usenet poster
 
Posts: n/a
Default Query to replace unwanted characters

Hi

How can I replace all characters except a-b,A-B,0-9 and hyphen from a field
in a table?

Thanks

Regards


  #2  
Old January 22nd, 2006, 02:02 PM posted to microsoft.public.access.queries
external usenet poster
 
Posts: n/a
Default Query to replace unwanted characters

John

Will depend on which version of Access you are using. Does your version
have the Replace() function?

Or, instead of a query, have you tried the find/replace choice from the Edit
menu?

--
Regards

Jeff Boyce
Office/Access MVP

"John" wrote in message
...
Hi

How can I replace all characters except a-b,A-B,0-9 and hyphen from a

field
in a table?

Thanks

Regards



  #3  
Old January 22nd, 2006, 03:52 PM posted to microsoft.public.access.queries
external usenet poster
 
Posts: n/a
Default Query to replace unwanted characters

I would suggest that you need a custom function written in VBA to do this. HEre
is a copy of a function from my library to get only numbers. You can modify
that by changing the strNumbers constant to
Const strNumbers As String = "0123456789AB-"

After copying the code to a module, modifying it, and saving it (module name
must be different than the code modMyFunction), you can call it in your SQL statement.

Field: fStripToNumbersOnly([YourTableName].[yourFieldName])

Or if you are using an update query.
Field: YourFieldName
Criteria: Like "*[!-0123456789AB]*"
Update to: fStripToNumbersOnly([YourTableName].[yourFieldName])

Public Function fStripToNumbersOnly(ByVal varText As Variant) As String
'Takes input and returns only the numbers in the input. Strips out
'all other characters. Handles dates, numbers, and strings.
'returns a string

Const strNumbers As String = "0123456789"
Dim strOut As String
Dim intCount As Integer

If Len(varText & "") = 0 Then
strOut = ""

Else
varText = varText & ""
For intCount = 1 To Len(varText)
If InStr(1, strNumbers, Mid(varText, intCount, 1)) 0 Then
strOut = strOut & Mid(varText, intCount, 1)
End If
Next intCount
End If

fStripToNumbersOnly = strOut

End Function



Jeff Boyce wrote:

John

Will depend on which version of Access you are using. Does your version
have the Replace() function?

Or, instead of a query, have you tried the find/replace choice from the Edit
menu?

--
Regards

Jeff Boyce
Office/Access MVP

"John" wrote in message
...
Hi

How can I replace all characters except a-b,A-B,0-9 and hyphen from a

field
in a table?

Thanks

Regards


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Cross tab query construction with Subqueries Steven Cheng Running & Setting Up Queries 7 February 13th, 2006 06:52 PM
Get External Data - not editable using Query Wizard MargaretBeckbury General Discussion 7 January 17th, 2006 09:13 AM
Crosstab Query Help Becks New Users 17 October 11th, 2005 08:31 PM
Moving from xBase/Clipper [email protected] New Users 1 February 3rd, 2005 07:25 PM
Union query is displaying Chinese characters for one of the fields Seth Schwarm Running & Setting Up Queries 4 January 27th, 2005 04:26 PM


All times are GMT +1. The time now is 11:58 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.