INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

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

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

(OP)
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

RE: Removing one of two of the leading characters in a table field

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.

RE: Removing one of two of the leading characters in a table field

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 ...

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

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

RE: Removing one of two of the leading characters in a table field

(OP)
Thank you MajP & Tony!

RE: Removing one of two of the leading characters in a table field

(OP)
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

RE: Removing one of two of the leading characters in a table field

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.

RE: Removing one of two of the leading characters in a table field

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.

RE: Removing one of two of the leading characters in a table field

(OP)
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!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close