PROPER function (1 Viewer)

Portucale

Registered User.
Local time
Today, 21:58
Joined
Sep 7, 2012
Messages
32
Hi,

I have a small issue where I do have names written in UPPER CASE, I would like to transform them in Capitalized (each word), I understand that I cannot use the same function as in excel (PROPER) but something like StrConv, but as I do have a ‘comma’ in between the names I have something like that
Code:
StrConv(Left(Tbl_Telephony_Temp.Agent, InStr(Tbl_Telephony_Temp.Agent, ",")-1), 3)&", "&StrConv(Mid(Tbl_Telephony_Temp.Agent, InStr(Tbl_Telephony_Temp.Agent, ",") + 1), 3) AS CompleteName
Which as you can see is quite a complex statement, any idea how can I simplify it?

Example of a name: VITOR, FONSECA, preferable output, Vitor, Fonseca

All the help and any help are very much appreciated.

Cheers
 

pr2-eugin

Super Moderator
Local time
Today, 21:58
Joined
Nov 30, 2011
Messages
8,494
Why are you worried about commas in the first place? It would just be fine with comma..
Code:
? StrConv("VITOR, FONSECA", vbProperCase)
Vitor, Fonseca

? StrConv("VITOR FONSECA", 3)
Vitor Fonseca
 

pr2-eugin

Super Moderator
Local time
Today, 21:58
Joined
Nov 30, 2011
Messages
8,494
Portucale, I am sure Bob has enough experience to suggest it.. Further more I have tested it. Rest assured it will provide the right result. ;)
 

bob fitz

AWF VIP
Local time
Today, 21:58
Joined
May 23, 2011
Messages
4,726
Portucale, I am sure Bob has enough experience to suggest it.. Further more I have tested it. Rest assured it will provide the right result. ;)
Yes, I also know that it returns the required result because I tested before I posted. Just curious about the result suggested by the OP.:mad:
 

Portucale

Registered User.
Local time
Today, 21:58
Joined
Sep 7, 2012
Messages
32
Hi,

I am not saying it doesn't work, but I must be doing something wrong as it didn't work for me...

This is what i get when I use the StrConv(Tbl_Telephony_Temp.Agent,3)

Agent Expr1001

MCLAUGHLIN,ALLAN Mclaughlin,allan

I am confused!!:banghead:

Thanks guys for the help, and rest assured that I NEVER criticize anyone
 

bob fitz

AWF VIP
Local time
Today, 21:58
Joined
May 23, 2011
Messages
4,726
Where are you using it (Querry? Contol Source property?)
 

Portucale

Registered User.
Local time
Today, 21:58
Joined
Sep 7, 2012
Messages
32
Hi Bob,
Using in Access 2010 in a query. But I think I find out why is not working for me... there isn't any blank space after the 'comma'... so seems that is recognizing the whole word as one and not as two.:banghead:
 

bob fitz

AWF VIP
Local time
Today, 21:58
Joined
May 23, 2011
Messages
4,726
Try:
StrConv(Replace([Tbl_Telephony_Temp.Agent],","," "),3)
 

Portucale

Registered User.
Local time
Today, 21:58
Joined
Sep 7, 2012
Messages
32
Thanks Bob, works like a dream, although I've just noticed that the first part is in fact the Surname and the Forename is after the comma, is there any way to revert the names :)

Try:
StrConv(Replace([Tbl_Telephony_Temp.Agent],","," "),3)
 

pr2-eugin

Super Moderator
Local time
Today, 21:58
Joined
Nov 30, 2011
Messages
8,494
You can use this function.
Code:
Public Function properName(inputStr As String) As String
[COLOR=Green]'**********************
'Code Courtesy of
'  Paul Eugin
'**********************[/COLOR]
    Dim tmpStr As String
    tmpStr = Mid(inputStr, InStr(inputStr, ",") + 1)
    tmpStr = tmpStr & " " & Mid(inputStr, 1, InStr(inputStr, ",") - 1)
    properName = Trim(StrConv(tmpStr, vbProperCase))
End Function
Put this code in a Standard module. Compile the code, then you can use it in immediate window as..
Code:
? properName("Francis , Paul")
Paul Francis
Or in a Query as..
Code:
FullName : properName([Tbl_Telephony_Temp].[Agent])
 

Portucale

Registered User.
Local time
Today, 21:58
Joined
Sep 7, 2012
Messages
32
Hi Paul,

Thanks for the help, but I am having issues with putting it to work, see pic, am I doing anything wrong?



It works OK in the Immediate Window, but for some reason not in the query :banghead:

Cheers
 

pr2-eugin

Super Moderator
Local time
Today, 21:58
Joined
Nov 30, 2011
Messages
8,494
If you are using it in SQL query it should be used as..
Code:
SELECT ProperName([Tbl_Telephony_Temp].[Agent])[COLOR=Red][B] As FullName[/B] [/COLOR]
FROM Tbl_Telephony_Temp
WHERE Tbl_Telephony_Temp......
Not
Code:
SELECT [COLOR=Blue][B]FullName: [/B][/COLOR]ProperName([Tbl_Telephony_Temp].[Agent])
FROM Tbl_Telephony_Temp
WHERE Tbl_Telephony_Temp......
 

Portucale

Registered User.
Local time
Today, 21:58
Joined
Sep 7, 2012
Messages
32
Hi Paul,
I am going crazy, tried so many different things that I haven't realized that the first instance was to be entered in the design mode... Thanks Paul and Bob for the help
 

Portucale

Registered User.
Local time
Today, 21:58
Joined
Sep 7, 2012
Messages
32
Hi Paul,

The code works perfect for the names that have a "space" after the 'comma' but in fact I do have some names without the space, like; Vitor,Fonseca and Vitor, Fonseca, can you help?

I managed to get the full name for the names without the space (Vitor,Fonseca, but the result is Vitor Fonseca,) the code I used is:
Code:
 tmpStr = tmpStr & " " & Mid(inputStr, 1, InStr(inputStr, ","))

Thanks,

You can use this function.
Code:
Public Function properName(inputStr As String) As String
[COLOR=Green]'**********************
'Code Courtesy of
'  Paul Eugin
'**********************[/COLOR]
    Dim tmpStr As String
    tmpStr = Mid(inputStr, InStr(inputStr, ",") + 1)
    tmpStr = tmpStr & " " & Mid(inputStr, 1, InStr(inputStr, ",") - 1)
    properName = Trim(StrConv(tmpStr, vbProperCase))
End Function
Put this code in a Standard module. Compile the code, then you can use it in immediate window as..
Code:
? properName("Francis , Paul")
Paul Francis
Or in a Query as..
Code:
FullName : properName([Tbl_Telephony_Temp].[Agent])
 

pr2-eugin

Super Moderator
Local time
Today, 21:58
Joined
Nov 30, 2011
Messages
8,494
No, I have validated the code before posting..
Code:
[COLOR=Green]'One space [B][U]after[/U] [/B]Comma[/COLOR]
? properName("Francis, Paul")
Paul Francis
[COLOR=Green]'One space [B][U]before[/U] [/B]Comma[/COLOR]
? properName("Francis ,Paul")
Paul Francis
[COLOR=Green]'One space [B][U]before[/U] and [U]after[/U][/B] Comma[/COLOR]
? properName("Francis , Paul")
Paul Francis
[COLOR=Green]'[U][B]No space[/B][/U] but a Comma[/COLOR]
? properName("Francis,Paul")
Paul Francis
It works fine for me..
 

Portucale

Registered User.
Local time
Today, 21:58
Joined
Sep 7, 2012
Messages
32
Yes it works also for me, but when I run the query it gives me a Run-time error '5': Invalid procedure or argument.No idea what could be possible causing that :banghead:
 

Users who are viewing this thread

Top Bottom