Results 1 to 7 of 7
  1. #1
    Juan4412 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2010
    Posts
    209

    Remove First Character

    Textbox on form, sometimes people are adding a comma to start the text or a space to add the text, is there a way to trim the string if the first character is a text or a space? To make it more difficult (for me at least) it is concatenating 2 fields so I can't just simply use the left function to trim the 1st 2 characters.



    My current syntax is this:
    Code:
    CombineTextFields: [textbox1] &" "+[textbox2]

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    Try:

    Trim(Replace(textbox1,",",""))
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Juan4412 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2010
    Posts
    209
    Quote Originally Posted by June7 View Post
    Try:

    Trim(Replace(textbox1,",",""))
    That removes all commas from the string, I only want to remove it if it is the 1st two characters in the string.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    Consistency is critical in string manipulation. Otherwise gets complicated. The comma could be first or preceded by space?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Juan4412 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2010
    Posts
    209
    Correct it will either be space, or ,space those are the 2 scenarios that I am trying to "idiot proof" and go ahead and remove if possible from the query resul.ts.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    No such thing as 'idiot proof' - always a better idiot.

    But try:

    IIf(Left(Trim(textbox1),1)=",", Mid(Trim(textbox1),2), Trim(textbox1))
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    If this is something you can control during data entry, suggest you do it there so don't have to do this manipulation every time you want to build a query.

    Code behind form in textbox AfterUpdate event can do this correction and make sure data is saved properly.

    If Not IsNull(Me.textbox1) Then Me.textbox1 = IIf(Left(Trim(textbox1),1)=",", Mid(Trim(textbox1),2), Trim(textbox1))
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Dealing with the # character
    By frankivalli in forum Access
    Replies: 2
    Last Post: 06-12-2014, 10:57 AM
  2. update/remove character from field
    By Ruegen in forum Queries
    Replies: 6
    Last Post: 01-23-2014, 05:08 PM
  3. Add character's to text box
    By Joopster in forum Forms
    Replies: 1
    Last Post: 03-20-2013, 06:45 PM
  4. 4th character of a field
    By Rhubie in forum Access
    Replies: 20
    Last Post: 08-28-2012, 04:04 PM
  5. Character Limits
    By nashr1928 in forum Reports
    Replies: 5
    Last Post: 12-08-2010, 01:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums