Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / New Users / April 2008

Tip: Looking for answers? Try searching our database.

Error on parse name

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
TimH - 09 Apr 2008 21:43 GMT
I have the code for parse name(giving credit to original coder)  and as I
study the code I get an error that FirstName is zero length even though it is
fully entered such as LastName, FirsName

If there is a middle name the error does not show up

Here is the  code for the  parse name :

Function ParseName(strOutSal As String, strOutFirst As String, _
                  strOutMiddle As String, strOutFinal As String, _
                  strOutSuffix As String, ByVal strInName As Variant) As
Integer
'
' Purpose:      Parse a full name into its constituent parts
' Arguments:    strOutSal       Salutation          Output
'               strOutFirst     First name          Output
'               strOutMiddle    Middle name         Output
'               strOutFinal     Last name           Output
'               strOutSuffix    Suffix              Output
'               strInName       Name to parse
' Returns:      Hex flag value, determining which components were filled in
' Author:       David Sussman
' Date:         8 June 1997

   Dim strTemp()       As String       ' Temporary work string
   Dim intCount        As Integer      ' No. of elements in above string
   Dim intSpacePos     As Integer      ' Position in string of space
   Dim intLoop         As Integer      ' Loop index
   Dim intParsename    As Integer      ' Return value
   Dim intMainCount    As Integer      ' No. of elements - prefix & suffix
   
   ParseName = 0
   ReDim strTemp(0) As String
   
   ' exit if name is blank, or add trailing space
   ' to ensure the InStr does not fail
   If IsBlank(strInName) Then Exit Function
   strInName = Trim$(strInName) & " "
   
   ' break the string into an array
   intSpacePos = InStr(strInName, " ")
   Do Until intSpacePos = 0
       ReDim Preserve strTemp(UBound(strTemp) + 1)
       strTemp(UBound(strTemp)) = Trim$(Left$(strInName, intSpacePos - 1))
       strInName = LTrim$(Right$(strInName, Len(strInName) - intSpacePos))
       intSpacePos = InStr(strInName, " ")
   Loop
   
   intCount = UBound(strTemp)
   intMainCount = intCount
   
   ' is there a prefix
   If InStr(csPREFIX_LIST, "." & UCase$(strTemp(1)) & ".") Then
       intParsename = intParsename Or csNAME_SAL
       strOutSal = strTemp(1)
       intMainCount = intMainCount - 1
   End If
   
   ' is there a suffix
   If InStr(csSUFFIX_LIST, "." & UCase$(strTemp(intCount)) & ".") Then
       intParsename = intParsename Or csNAME_SUFFIX
       strOutSuffix = strTemp(intCount)
       intMainCount = intMainCount - 1
   End If
   
   ' How many elements are left
   Select Case intMainCount
   Case 0
   Case 1
       ' one element left - must be the surname
       If (intParsename And csNAME_SAL) Then
           strOutFinal = strTemp(2)
       Else
           strOutFinal = strTemp(1)
       End If
       intParsename = intParsename Or csNAME_LAST
   Case 2
       ' two elements left - first surname and name
     
       If (intParsename And csNAME_SUFFIX) Then
           strOutFinal = strTemp(intCount - 1)
       Else
           strOutFinal = strTemp(intCount)
       End If
       intParsename = intParsename Or csNAME_LAST
       
       If (intParsename And csNAME_SAL) Then
           strOutFirst = strTemp(2)
       Else
           strOutFirst = strTemp(1)
       End If
       intParsename = intParsename Or csNAME_FIRST
   Case Else
   
       ' three or more elements - first name, surname
       ' and one or more middle names
       If (intParsename And csNAME_SAL) Then
           strOutFirst = strTemp(2)
       Else
           strOutFirst = strTemp(1)
       End If
       intParsename = intParsename Or csNAME_LAST
   
       If (intParsename And csNAME_SUFFIX) Then
           strOutFinal = strTemp(intCount - 1)
       Else
           strOutFinal = strTemp(intCount)
       End If
       intParsename = intParsename Or csNAME_FIRST
   
       ' middle names
       For intLoop = 2 To intMainCount - 1
           If (intParsename And csNAME_SAL) Then
               strOutMiddle = Trim$(strOutMiddle) & " " & strTemp(intLoop +
1)
           Else
               strOutMiddle = Trim$(strOutMiddle) & " " & strTemp(intLoop)
           End If
           intParsename = intParsename Or csNAME_MID
       Next
       strOutMiddle = Trim$(strOutMiddle)
   End Select
   
   ParseName = intParsename

End Function
Signature

timH

Margaret Bartley - 29 Apr 2008 02:09 GMT
Step through the code.  Using the Command window and the Locals window, you
should be able to identify where a variable has an unexpected value.

At that point, if you try to articulate a specific question to the group,
you'll probably answer it yourself.

>I have the code for parse name(giving credit to original coder)  and as I
> study the code I get an error that FirstName is zero length even though it
[quoted text clipped - 125 lines]
>
> End Function
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.