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. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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 | |
|
|
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 |