Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Feb 2004
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Removing Characters from field(s) (2000)

    I need to remove specific characters from a field in a database I created.


    The way I do it now is to do a Query to bring up the records/fields that contain (eg. A hyphen or a period etc.) and then manually edit them. This can take a long time, and, there has to be a way to ask the program to do it and I haven

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Removing Characters from field(s) (2000)

    If you want to remove ALL occurrences of a character from a field, you can use a custom function and an update query.

    1. Create a new module (from the Modules section of the database) and enter the following custom function:

    Public Function MyReplace(aValue As Variant, sWhat As String, sBy As String) As Variant
    If IsNull(aValue) Then
    MyReplace = Null
    Else
    MyReplace = Replace(aValue, sWhat, sBy)
    End If
    End Function

    2. Create a query based on your table.
    Add the field you want to modify to the query design grid.
    Select Query | Update Query.
    In the Update To line, enter

    MyReplace([FieldName], "-", "")

    where FieldName is the name of the field, and "-" stands for the character you want to remove.
    Run the query.

    3. If you want to automate this, you can call a query in code:

    DoCmd.OpenQuery "QueryName"

    where QueryName is the name of the query.

    Note: in Access 2000, it is not possible to use the Replace function in a query directly, you must do it through a custom function. In Access 2002 and later, you can use Replace directly.

  3. #3
    New Lounger
    Join Date
    Feb 2004
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Removing Characters from field(s) (2000)

    Thank You Hans!

    I'll give it a try...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •