• How do you trim the last letter in access 2003?

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » How do you trim the last letter in access 2003?

    Author
    Topic
    #479203

    If more then 1 letter is at the end of a persons name after the last space do nothing but if only 1 letter is after the name then take that letter off in access 2003?
    Smith,John A–I would want to get rid of the A
    but if it was Smith,John Ann-I don’t want it to do anything.

    Viewing 1 reply thread
    Author
    Replies
    • #1299925

      Try the following but substitute Name for the name of your control:

      Mid(Name, 1, IIf(Mid(Name, Len(Name)-1, 1) = ” “) , Instr(1, Name, Len(Name)-2), Instr(1, Name, Len(Name)))

    • #1299929

      If more then 1 letter is at the end of a persons name after the last space do nothing but if only 1 letter is after the name then take that letter off in access 2003?
      Smith,John A–I would want to get rid of the A
      but if it was Smith,John Ann-I don’t want it to do anything.

      What does “do nothing” mean? Just display the whole name as it is?

      Patt has used the Instr function. You can also use the InstrRev function which looks for things from the end rather than the beginning.

      InstrRev([txtName],” “) tells you the position of the last space, counted from the begining.
      InstrRev(“j smith a”,” “) =8

      So InstrRev([txtName],” “) = len([txtname])-1 is a test for whether the last space is one place from the end.

    Viewing 1 reply thread
    Reply To: How do you trim the last letter in access 2003?

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: