Results 1 to 9 of 9
  1. #1
    gmaster is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    May 2014
    Posts
    32

    Extract text from a textfield, removing last 3 characters

    Hi, i need to write a function that removes the last 3 digits from a certain text field....i tried with various Left, Right, Trim but i couldn't do it....


    Thanks

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    You need a couple of functions:

    = left(vWORD, LEN(vWORD)-3)

  3. #3
    gmaster is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    May 2014
    Posts
    32
    Hey thanks, works great!
    I'm also trying to use it making it pick the word from a combobox in a form:
    =Left([Forms]![IntroA]![Combobox], Len([Forms]![IntroA]![Combobox])-3)
    But in this case it gives me an error...you know why?

  4. #4
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    It would help if you said what the error was!

    If the combo box has more than one column, with the first column hidden (this is very common), then [Forms]![IntroA]![Combobox] refers to the first (hidden) column, and not the one you see. Try something like [Forms]![IntroA]![Combobox].column(1) to refer to the second column.

    John

  5. #5
    gmaster is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    May 2014
    Posts
    32
    Yeah, sorry...so the error it gives me is "#Type?" or else "#Name?" (i'm using it in a textbox for a report), and the problem seems to be in the second part of the function (if i only use the Left() it works, but if i add the Len() or the InStr() it gives me those errors...)
    Last edited by gmaster; 10-07-2014 at 03:38 AM.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Is the length of the string variable? Show example data.

    Is the combobox bound? Is it multi-column? Show the RowSource SQL.
    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
    gmaster is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    May 2014
    Posts
    32
    Yeah, the lenght is variable (Ex. Amil_BB, CMT_BB, Usher_BB, BRFA_BB.....as you can see, i was trying to get the name without the "_BB"), while the combobox isn't bound and single-column (this is its SQL: SELECT [PatList].[PatName] FROM PatList ORDER BY [PatName])

  8. #8
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    If the part to be removed is always "_BB", then you can use the replace function:

    replace( [Forms]![IntroA]![Combobox],"_BB","")


    In the report, try using VBA to populate the textbox: [textboxname] = Left([Forms]![IntroA]![Combobox], Len([Forms]![IntroA]![Combobox])-3)


    The form has to be open for this to work.

  9. #9
    gmaster is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    May 2014
    Posts
    32
    Thanks a lot everyone, i managed to make it work!!

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

Similar Threads

  1. Removing special characters
    By crowegreg in forum Queries
    Replies: 3
    Last Post: 02-26-2014, 11:56 AM
  2. Removing Text If Null
    By lewis1682 in forum Reports
    Replies: 1
    Last Post: 09-23-2013, 10:46 AM
  3. Removing text between parentheses.
    By jwhitley in forum Programming
    Replies: 3
    Last Post: 01-17-2013, 02:37 PM
  4. Removing certain characters from field
    By topp in forum Access
    Replies: 3
    Last Post: 01-08-2013, 12:36 PM
  5. Extract Text Data
    By tmcrouse in forum Queries
    Replies: 5
    Last Post: 05-25-2010, 11:34 AM

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