Replace a / in a string

  • Thread starter Thread starter Stever
  • Start date Start date
S

Stever

I can't seem to find a good way to replace a \ with a _ in a string.
For example, I have the string 'A/E Group' I would like the VBA to return
A_E Group.

Thanks in advance for any suggestions you may have.

Steve
 
I can't seem to find a good way to replace a \ with a _ in a string.
For example, I have the string 'A/E Group' I would like the VBA to return
A_E Group.

Thanks in advance for any suggestions you may have.

Steve

Which is it, the "\" or the "/" you wish to replace? :-)
How this is done is Access version dependent.
If you have Access 2000 or newer, in VBA:
[YourField] = Replace([YourField],"/","_")

You can use it in a Select query
Exp:Replace([YourField],"/","_")

Directly in a Control's Control Source it would be:
=Replace([YourField],"/","_")

Note: If memory serves me well, in early versions of Access 2000 you
will have to place the Replace function in a module. Then call the
module function from the query. It will work just as well.

In Access 97 you would have to write a full User Defined function to
locate and replace the character. If you need help with that, post
back.
 
Thanks that did the trick.

Steve



fredg said:
I can't seem to find a good way to replace a \ with a _ in a string.
For example, I have the string 'A/E Group' I would like the VBA to return
A_E Group.

Thanks in advance for any suggestions you may have.

Steve

Which is it, the "\" or the "/" you wish to replace? :-)
How this is done is Access version dependent.
If you have Access 2000 or newer, in VBA:
[YourField] = Replace([YourField],"/","_")

You can use it in a Select query
Exp:Replace([YourField],"/","_")

Directly in a Control's Control Source it would be:
=Replace([YourField],"/","_")

Note: If memory serves me well, in early versions of Access 2000 you
will have to place the Replace function in a module. Then call the
module function from the query. It will work just as well.

In Access 97 you would have to write a full User Defined function to
locate and replace the character. If you need help with that, post
back.
 
Back
Top