Re: Using the replace function



On Fri, 22 Dec 2006 09:13:01 -0800, dtoney wrote:

When I try this, it gives me an error... "Undefinded 'Replace' in expression"

"fredg" wrote:

On Tue, 16 Nov 2004 06:48:03 -0800, JC Newsgroup wrote:

I need to remove dashes "-" from a field:

My data looks like this: 111-11-1111 and I need it to look like this:
111111111. I've been told that I need to use an update query with the
Replace function. I have very little programming experience and I've been
unable to find any examples of this function. Can someone show me what
specifically I would have to type to make the replace function work for the
situation I've outlined and/or cite a place where I can find examples of this
function so that I may teach myself?

Thanks in advance

You wish to permanently change the data?
Are you sure it's not simply an Input Mask that is adding the hyphens,
while the data is actually stored without hyphens?

If the data does indeed have hyphens, then if you have a later version
of Access 2000 or newer.....

Back Up your current data.
Create a New Query.
Copy and Paste this into the Query's SQL Window.
Change the Table and Field Names as needed.

Update YourTable Set YourTable.[FieldName] =
Replace([FieldName],"-","");

--
Fred
Please only reply to this newsgroup.
I do not reply to personal email.


Do you have Access 2000 or newer?
Some earlier versions of Access 2000 require that you create a user
defined function (in a module) then call that function from the query.

Function ReplaceText(StringIn as String) as String
ReplaceText = Replace([StringIn],"-","")
End Function

Then call it from the query:
Update YourTable Set YourTable.[FieldName] = ReplaceText([FieldName]);

Newer Access 2000 as well as 2002, 2003, you can use Replace directly
in the query..
If this still throws an error, check your references.

Open any module in Design view (or click Ctrl + G).
On the Tools menu, click References.
Click to clear the check box for the type library or object library
marked as "Missing:."

An alternative to removing the reference is to restore the referenced
file to the path specified in the References dialog box. If the
referenced file is in a new location, clear the "Missing:" reference
and create a new reference to the file in its new folder.

See Microsoft KnowledgeBase articles:
283115 'ACC2002: References That You Must Set When You Work with
Microsoft Access'
Or for Access 97:
175484 'References to Set When Working With Microsoft Access' for
the correct ones needed,
and
160870 'VBA Functions Break in Database with Missing References' for
how to reset a missing one.

For even more information, see
http://www.accessmvp.com/djsteele/AccessReferenceErrors.html

--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
.



Relevant Pages

  • RE: IIf IsNull() Complile Error
    ... Microsoft Access 10.0 Object Library ... there is most likely something wrong with your references. ... Jerry Whittle, Microsoft Access MVP ... same error "Compile Error in Query Expression", and the SQL now reads as ...
    (microsoft.public.access.queries)
  • Re: Addnew method/Dynamic Array
    ... stored in a Public Function called GetBatchNumbers() within the current form. ... I created a query detailing all the fields the user needs to see with the ... I'm an aspiring programmer, working in my first IT related ... to qualify the control references with "Me". ...
    (microsoft.public.access.modulesdaovba)
  • Re: Access Crashes When Rt Click Build in Query Design View
    ... And it will happen on more than one query in the database. ... Compact the database to get rid of this junk: ... Choose References from the Tools menu. ...
    (comp.databases.ms-access)
  • Re: Error 3464 with dCount - some computers only
    ... a minor correction to my original post. ... The SQL for the query which is producing the error in the dcount statement ... restarted and re-installed all references ... Reference lists on both computers again identical. ...
    (microsoft.public.access.formscoding)
  • Re: I need update query to run from combo box
    ... for someone trying to learn how to do VBA. ... > The query just won't run with the criteria As I said it runs fine when I ... > Microsoft Access 9.0 Object Library ... that implies that you have not set your References ...
    (microsoft.public.access.queries)