Extracting from a variable

  • Thread starter Thread starter Ian
  • Start date Start date
I

Ian

Hi,

Thanks in advance.

I am writing letters and all I have is fornames field.

I wish to address a letter to just initals

My question is how do i extract the initals from the
fornames.

I know of one that has 5 fornames ie. Peter Raymod Alan
Paul Matthew and want P R A P M

Thanks again in Advance

Ian
 
If you're using Access 2000 or newer, you can use the Split function to
convert your string into an array of individual names, and then extract the
first letter from each name. Something like the following untested aircode:

Dim intLoop As Integer
Dim strInitials As String
Dim varNames As Variant

varNames = Split(FullName, " ")
If IsNull(varNames) = False Then
For intLoop = LBound(varNames) To UBound(varNames)
strInitials = strInitials & UCase(Left(varNames(intLoop), 1) & " "
Next intLoop
End If
 
You'll need to get into some code to try this.

Use the Split() function to fill an array then loop through
the array using Left$(array,1) to get the first character
and concatenate a string to use for the address initials.

Air code **** Not tested

Public Function InitFromName(strForeNames as String) as
String

Dim saForeInits() as String, intI as integer

saForeInits = Split(strForeNames)

For intI = 0 to UBound(saForeInits) - 1
InitFromName = InitFromName & saForeInits(intI) & Chr32
Next I

End Function
 
Damn I lost track of what I was trying to do there... :-))

Doug's code is better anyway - use that.
 
Thanks Doug,

It looks good but I just cant get it to work it says:-

Syntax error and I can't see the error

Sorry to ask for help once again

regards Ian
 
strInitials = strInitials & UCase(Left(varNames (intLoop),
1) & " "

There's a parentheses missing from just after the number 1.

Should be:
strInitials = strInitials & UCase(Left(varNames (intLoop),
1)) & " "
 
You're welcome. Another pair of eyes always handy, now if I
can just find _my_ spare ones..... :-))
 
Back
Top