UtterAccess HomeUtterAccess Wiki

Welcome Guest ( Log In | Register )

Custom Search
Edit Discussion
> BuildName    
Function Information
Applicable Versions

Any

Dependancies

- VBA
- eNameProperties (as noted in function comments)

This function builds a name with the specified components. Particularly useful in queries.

CODE

' Code courtesy of UtterAccess Wiki
' http://www.utteraccess.com/wiki/index.php/Category:FunctionLibrary
'
' You are free to use this code in any application,
' provided this notice is left unchanged.
'
' REV  DATE                          DESCRIPTION
' 1.0  2010-08-13              initial release
' 1.1  2010-09-12              revised function header
'
'==============================================================================
' NAME: BuildName
' DESC: Builds a name structure from the passed arguments
' ARGS: sLast:     Last Name
'       sFirst:    First Name
'       lNameProp: Bitwise value for naming structure (eNameProperty)
'       sSalut:    Salutation (Mr., Mrs., Dr.)
'       sOridinal: Name Ordinal (I, IV etc)
'       sTitle:    Title (ex. CEO, Systems Aministrator, etc.)
'
' INCLUDE THIS IN THE MODULE DECLARATION
' Public Enum eNameProperties
'   enpFirst = 0
'   enpLast = 1
'   enpMiddle = 2
'   enpOrdinal = 4
'   enpSalutation = 8
'   enpTitle = 16
' End Enum
'
' EXAMPLE CALL
' ?BuildName("Leach", "Jack", enpFirst+enpLast+enpTitle+enpSalutation, , "Mr.", , "General Mananger"
' Returns: Mr. Jack Leach, General Mananger
'==============================================================================
'ErrStrV3.00
Public Function BuildName( _
   sLast As String, _
   sFirst As String, _
   lNameProp As eNameProperties, _
   Optional sMiddle As String = "", _
   Optional sSalut As String = "", _
   Optional sOrdinal As String = "", _
   Optional sTitle As String = "" _
   ) As String
On Error GoTo Error_Proc
Dim Ret As String
'=========================

'=========================

 Ret = " " & Trim(sFirst) & " "
 
 If (lNameProp And enpMiddle) Then Ret = Ret & " " & Trim(sMiddle) & " "
 If (lNameProp And enpLast) Then Ret = Ret & " " & Trim(sLast) & " "
 If (lNameProp And enpSalutation) Then Ret = Trim(sSalut) & " " & Ret
 If (lNameProp And enpOrdinal) Then Ret = Ret & " " & Trim(sOrdinal) & " "
 If (lNameProp And enpTitle) Then Ret = RTrim(Ret) & ", " & Trim(sTitle)
 
 Ret = Trim(Replace(Ret, "  ", " "))
 
'=========================
Exit_Proc:
 BuildName = Ret
 Exit Function
Error_Proc:
 MsgBox "Error: " & Trim(str(Err.Number)) & vbCrLf & _
   "Desc: " & Err.Description & vbCrLf & vbCrLf & _
   "Procedure: BuildName" _
   , vbCritical, "Error!"
 Resume Exit_Proc
 Resume
End Function



Creative Commons License
BuildName by UtterAccess Wiki is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Editing and revision of the content is freely encouraged; for details, see Expected Usage.

Edit Discussion
Custom Search
Thank you for your support!
This page has been accessed 4,886 times.  This page was last modified 12:52, 6 September 2012 by Jack Leach.   Disclaimers