By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,336 Members | 2,307 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,336 IT Pros & Developers. It's quick & easy.

help with selecting first 2 letters in string

P: n/a
I have a string surname and want to select the first two letters to
use in a code field
how can i check if the second item in string is an apostrophe and
filter it out ' in names such as o'brien and use the third item in
string so i get ob

in other words if surname = brown code =br
but if surname = o'brien code = ob

colm
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Something like the following untested air-code should work:

Function ReturnLetters(InputName As String) As String

Dim intLoop As Integer
Dim intSelected As Integer
Dim strCurrLetter As String
Dim strCode As String

For intLoop = 1 to Len(InputName)
strCurrLetter = Mid(InputName, intLoop, 1)
If (strCurrLetter >= "a" And strCurrLetter <= "z") Or _
(strCurrLetter >= "A" And strCurrLetter <= "Z")
strCode = strCode & strCurrLetter
intSelected = intSelected + 1
If intSelected = 2 Then
Exit For
End If
End If
Next intLoop

ReturnLetters = strCode

End Function

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

"colm" <cobrien@don'tsendmespam.btinternet.com> wrote in message
news:mh********************************@4ax.com...
I have a string surname and want to select the first two letters to
use in a code field
how can i check if the second item in string is an apostrophe and
filter it out ' in names such as o'brien and use the third item in
string so i get ob

in other words if surname = brown code =br
but if surname = o'brien code = ob

colm

Nov 13 '05 #2

P: n/a
On Tue, 26 Oct 2004 21:52:07 +0000 (UTC), colm wrote:
I have a string surname and want to select the first two letters to
use in a code field
how can i check if the second item in string is an apostrophe and
filter it out ' in names such as o'brien and use the third item in
string so i get ob

in other words if surname = brown code =br
but if surname = o'brien code = ob

colm


=IIf(Mid([LastName],2,1)="'",Left([LastName],1) &
Mid([LastName],3,1),Left([LastName],2))

--
Fred
Please only reply to this newsgroup.
I do not reply to personal email.
Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.