mid function

  • Thread starter Thread starter MK
  • Start date Start date
M

MK

Can someone explain (in English) how this pulls the first
name from--
doe, john
(*field is called name)

mid([name], InStr(1, [name], ",")+2)

I just don't understand the programming and would like
to...

Thanks
 
MK said:
Can someone explain (in English) how this pulls the first
name from--
doe, john
(*field is called name)

mid([name], InStr(1, [name], ",")+2)

I just don't understand the programming and would like
to...


InStr(1, [name], ",") looks for the first occurance (after
position 1) of a comma in the name field. it returns the
character position of the comma, in your example 4.

mid([name], 4+2) extracts the remainder of the name field
starting with the position in its second argument, 6 thus
getting Joe.

Both of these functions have options and return values
beyond those demonstrated by this usage, so check Help for
more details.

Warning Name is an Access reserved word and you should not
use it for your own purposes to avoid all kinds of possible
confusion.
 
1) Find the position of the comma:
InStr(start search at character x, text to search, character to search for)
= 1st position of specified character within "text to search" (0 if not
found)
In your example: InStr(1, [name], ",") = position of the first occurance of
a comma within [name]

2) Get the first name:
The arguments of the Mid function are as follows:
mid(text to search, starting character, [optional: # of characters to
return])
If the 3rd argument is not supplied (which it isn't in your example), all
text from Starting character to the end of string will be returned..
So, in your example Mid([Name], starting with 2nd character after 1st comma)
returns "Joe"

HTH,
 
Back
Top