I want to delete all charters on the right side of the last comma.

Jon123

Registered User.
Local time
Today, 05:46
Joined
Aug 29, 2003
Messages
668
Raw data
aaa, bb, ccc, dd
or
aa, bbb, cc

I want field1 to be
aaa, bb, ccc
or
aa, bbb


This drops everything to the right of the 1st comma
field1 would = dd
or cc

Code:
  Me.field1 = (Right([field1], (InStr(1, [field1], ",") - 1)))

This drops everything from the 1st comma on the left to the end.
field 1 would = aaa
or aa

Code:
  Me.field1 = (Left([field1], (InStr(1, [field1], ",") - 1)))
 
I've not used it but there is an InstrRev() function which works like Instr() but right to left rather than left to right.

There is an example on that page for removing extensions from filenames.

Code:
Left([Filename],InStrRev([Filename],".")-1)

Perhaps it would work if you adapted the expression to look for the "," instead of the "."

Code:
Left([Filename],InStrRev([Filename],",")-1)
 
sorry I dont follow? I thought I was looking for the ","
 
You were, but the code in the original example wasn't, it was looking for the "."

Code:
Left([Filename],InStrRev([Filename],"[COLOR="Red"].[/COLOR]")-1)

This code is looking to remove the file extension "file.txt"

Which is why I mentioned about changing it to look for the "," instead.

Code:
Left([Filename],InStrRev([Filename],"[COLOR="Red"],[/COLOR]")-1)
 
got it, tried it and I'm getting a type mismatch error.
 
So that's ..

Code:
Me.field1 = Left(Me.field1, InStrRev(Me.field1, ",") -1)

You may need to account for null fields.

Code:
If Len(Me.Field1 & vbNullString) > 0 Then Me.field1 = Left(Me.field1, InStrRev(Me.field1, ",") -1)
 
I had an extra () when inputting it into my code. This works great . Thank you so much.
 

Users who are viewing this thread

Back
Top Bottom