Discussion:
Remove only the last comma
(too old to reply)
Garry
2013-04-24 15:09:00 UTC
Permalink
Hi

I need to remove or replace with "" only the last comma in a field

from: Bill, John, Matt, Fred,

to : Bill, John, Matt, Fred

Any help would be appreciated, have tried Replace([Field],"*,","") but no
good

Cheers
ralph
2013-04-24 15:53:01 UTC
Permalink
On Wed, 24 Apr 2013 16:09:00 +0100, "Garry"
Post by Garry
Hi
I need to remove or replace with "" only the last comma in a field
from: Bill, John, Matt, Fred,
to : Bill, John, Matt, Fred
Any help would be appreciated, have tried Replace([Field],"*,","") but no
good
Cheers
s = Left(s, Len(s) + (Right(s, 1)= ","))

or

s = Left(s, Len(s) - 1)

???
-ralph
Garry
2013-04-25 08:31:41 UTC
Permalink
Thanks Ralf

What about removing only the very first comma in a string

On this occasion by the way it would always follow a number only

Cheers, Garry
Post by ralph
On Wed, 24 Apr 2013 16:09:00 +0100, "Garry"
Post by Garry
Hi
I need to remove or replace with "" only the last comma in a field
from: Bill, John, Matt, Fred,
to : Bill, John, Matt, Fred
Any help would be appreciated, have tried Replace([Field],"*,","") but no
good
Cheers
s = Left(s, Len(s) + (Right(s, 1)= ","))
or
s = Left(s, Len(s) - 1)
???
-ralph
ralph
2013-04-25 17:39:40 UTC
Permalink
On Thu, 25 Apr 2013 09:31:41 +0100, "Garry"
Post by Garry
Thanks Ralf
What about removing only the very first comma in a string
On this occasion by the way it would always follow a number only
Still too many variables...

Try using Instr() to find the first comma (or perhaps the first
comma and space).
Then use Right() to retrieve everything after into a new string.

But you can work out this solution as well as many others by simply
visiting the VBA String handling functions and playing a bit.
Here is a simple review. Note the part about either doing the
functions in one statement after the other, or combining then into a
single statement.
http://ycmi.med.yale.edu/nadkarni/access_course/String_Frame.htm

Here is another site illustrating an assortment of various solutions
to all kinds of problems.
http://dmcritchie.mvps.org/excel/strings.htm

Simple googling will come up with many more.

Note: When it comes to string handling the VBA functions are identical
for Excel and VB, so don't just limit yourself to MS Access sites.

-ralph
Garry
2013-04-26 08:05:41 UTC
Permalink
Thanks Ralph, great help, Cheers, Garry
Post by ralph
On Thu, 25 Apr 2013 09:31:41 +0100, "Garry"
Post by Garry
Thanks Ralf
What about removing only the very first comma in a string
On this occasion by the way it would always follow a number only
Still too many variables...
Try using Instr() to find the first comma (or perhaps the first
comma and space).
Then use Right() to retrieve everything after into a new string.
But you can work out this solution as well as many others by simply
visiting the VBA String handling functions and playing a bit.
Here is a simple review. Note the part about either doing the
functions in one statement after the other, or combining then into a
single statement.
http://ycmi.med.yale.edu/nadkarni/access_course/String_Frame.htm
Here is another site illustrating an assortment of various solutions
to all kinds of problems.
http://dmcritchie.mvps.org/excel/strings.htm
Simple googling will come up with many more.
Note: When it comes to string handling the VBA functions are identical
for Excel and VB, so don't just limit yourself to MS Access sites.
-ralph
Loading...