Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing one of two of the leading characters in a table field 2

Status
Not open for further replies.

irethedo

Technical User
Feb 8, 2005
429
0
0
US
I have a field named SPNote in a table called Sameord_tbl that may have a leading ',' (comma) or a leading ' ,' (space comma)
that I would like to strip out of this field of all records in this table.

I was able to strip out the leading comma with the following but is there a way to delete either of these
two variations with the same query?

Code:
SPNote:Right([SameOrd_tbl].[SPNote],Len([SameOrd_tbl].[SPNote])-1)

Thanks
 
I would make a user defined function. Something like this untested

Code:
Public Function CleanNote(varNote as variant) as variant
  if not isnull(varNote) then
    CleanNote = trim(varNote)
    if left(Cleannote,1) = "," then
     CleanNote = mid(varnote,2)
    end if
  end if
end function

Then in Sql
Select CleanNote([Spnote]) as NewNote, other fields, from sometable

You can use this in an update query.
 
You can use simple functions in Access queries just as you would in VBA, so if all your values begin with [comma], or [space, comma], then ...

[tt][blue]SPNote:Mid([SameOrd_tbl].[SPNote],InStr([SameOrd_tbl].[SPNote],',')+1)[/blue][/tt]

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
I used Tony's suggestion in my query:

Code:
SPNote:Mid([SameOrd_tbl].[SPNote],InStr([SameOrd_tbl].[SPNote],',')+1)

But i just noticed that I have another field (MyLine) in this table (SameOrd_tbl) that might
start with ' ,' (space comma) but not all records have this leading (space comma)

Is there an easy way to test and remove the leading (space comma) from any records that have this?

Thanks again
 
You can use MajP's suggestion to do it to any field in your table, or any table.

Have fun.

---- Andy

There is a great need for a sarcasm font.
 
I would think Tony's code works for no leading characters, and space comma, but not comma.
example: ",SomeString"
Instr will look for space comma and will return 0. Then when you add 1 to the mid function it will return
",SomeString"
Assuming there are not other commas in the strings except leading commas you could
SPNote:Mid([SameOrd_tbl].[SPNote],InStr(Trim([SameOrd_tbl].[SPNote]),',')+1)

If there is a comma somewhere else in the text than do what I suggest.
It handles: No characters, empty space at beginning, comma at beginning, comma space at beginning.
 
Thanks MajP

I looked at this a little bit closer this morning before seeing your post and found this to be a better solution to handle both
fields in my table.

Thank you for your help with this!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top